Jump to content

Problem with gd script


Ozzapoo

Recommended Posts

Hey. I was trying to make a script that would allow me to generate images using gd, however I do not know what is wrong with it. It doesn't display and error but it doesn't generate an image either! Please have a look at it and tell me what's wrong :D

 

<?php

$width = $_POST['width']; 
if($width > 800) {
exit("Width is greater than 800"); }

$height = $_POST['height']; 
if($height > 500) {
exit("Height is greater than 500"); }

$type = $_POST['type'];
if ($type == "jpeg") { header ("Content-type: image/jpeg"); } elseif($type == "png") {header ("Content-type: image/png"); } elseif($type == "gif") 

{header ("Content-type: image/gif"); } else {exit("ERROR: Unknown Filetype?"); }

$bcolour = $_POST['bcolour']; 

$handle = ImageCreate ($width, $height) or die ("Cannot Create image"); 
if($bcolour = "white") { $bg_color = ImageColorAllocate ($handle, 255, 255, 255); } //white
elseif($tcolour = "red") { $bg_color = ImageColorAllocate ($handle, 255, 0, 0); } //red
elseif($tcolour = "blue") { $bg_color = ImageColorAllocate ($handle, 0, 0, 255); } //blue
elseif($tcolour = "green") { $bg_color = ImageColorAllocate ($handle, 0, 192, 0); } //green
elseif($tcolour = "yellow") { $bg_color = ImageColorAllocate ($handle, 255, 255, 0); } //yellow
elseif($tcolour = "orange") { $bg_color = ImageColorAllocate ($handle, 255, 153, 0); } //orange
elseif($tcolour = "lblue") { $bg_color = ImageColorAllocate ($handle, 173, 216, 230); } //light blue
elseif($tcolour = "purple") { $bg_color = ImageColorAllocate ($handle, 160, 32, 240); } //purple
else {exit("Unidentified Background Colour!"); }
$tcolour = $_POST['tcolour']; 
if($tcolour = "white") { $txt_color = ImageColorAllocate ($handle, 255, 255, 255); } //white
elseif($tcolour = "red") { $txt_color = ImageColorAllocate ($handle, 255, 0, 0); } //red
elseif($tcolour = "blue") { $txt_color = ImageColorAllocate ($handle, 0, 0, 255); } //blue
elseif($tcolour = "green") { $txt_color = ImageColorAllocate ($handle, 0, 192, 0); } //green
elseif($tcolour = "yellow") { $txt_color = ImageColorAllocate ($handle, 255, 255, 0); } //yellow
elseif($tcolour = "orange") { $txt_color = ImageColorAllocate ($handle, 255, 153, 0); } //orange
elseif($tcolour = "lblue") { $txt_color = ImageColorAllocate ($handle, 173, 216, 230); } //light blue
elseif($tcolour = "purple") { $txt_color = ImageColorAllocate ($handle, 160, 32, 240); } //purple
else {exit("Unidentified Text Colour!"); }



$tbeginX = $_POST['tbeginX']; 
$tbeginY = $_POST['tbeginY']; 
$size = $_POST['size']; 
$text = $_POST['text']; 

ImageTTFText ($handle, $size, 0, $tbeginX, $tbeginY, $txt_color, "fonts/arial.otf", $text); 

if ($type == "jpeg") { ImageJpg ($handle); } elseif($type == "png") {ImagePng ($handle); } elseif($type == "gif") {ImageGif ($handle); } else {exit

("ERROR: Unknown Filetype?"); }



?>

 

This script was based on the following code, which DOES work ( meaning gd does work on my computer )

 

<?php 
header ("Content-type: image/png"); 
$handle = ImageCreate (220, 65) or die ("Cannot Create image"); 
$bg_color = ImageColorAllocate ($handle, 255, 0, 0); 
$txt_color = ImageColorAllocate ($handle, 0, 0, 0); 
ImageTTFText ($handle, 35, 0, 15, 40, $txt_color, "fonts/bsps.otf", "test"); 
ImagePng ($handle); 

//The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text.
?>

Link to comment
Share on other sites

As derrick said add to the top of your code:

 

error_reporting(E_ALL);
ini_set('display_errors', true);

 

If you're testing it with a jpg image, it won't work because the function is

 

ImageJpeg, you used ImageJpg, which doesn't exist. Change it to ImageJpeg and see if it's any better.

 

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.