Ozzapoo Posted March 15, 2008 Share Posted March 15, 2008 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 <?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. ?> Quote Link to comment Share on other sites More sharing options...
derrick1123 Posted March 15, 2008 Share Posted March 15, 2008 error_reporting(E_ALL); Put that someone and see what happens.... Quote Link to comment Share on other sites More sharing options...
helraizer Posted March 15, 2008 Share Posted March 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
Ozzapoo Posted March 15, 2008 Author Share Posted March 15, 2008 Thanks guys!! I fixed it! I messed around with it so much that I accidentally swapped one of the values around >< Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.