cturner Posted August 11, 2007 Share Posted August 11, 2007 When I test the code that is below, it doesn't display the text on the image after it has been saved. Also when it saves the image, it only saves it as .jpeg and not the $pagetitle. Can someone please tell me how to solve those problems? Thanks in advance. // more code is above here function makeimage() { $button = str_replace(' ', '', $pagetitle); header("Content-type: image/jpeg"); $im = @imagecreate(200, 23) or die("Cannot Initialize new GD image stream."); $background_color = imagecolorallocate($im, 0, 57, 122); $text_color = imagecolorallocate($im, 255, 255, 255); imagestring($im, 3, 10, 5, $button, $text_color); $button2 = imagejpeg ($im, $button.".jpeg"); imagedestroy($im); } makeimage(); // more code is below here Link to comment https://forums.phpfreaks.com/topic/64351-image-not-saving-properly/ Share on other sites More sharing options...
KrisNz Posted August 11, 2007 Share Posted August 11, 2007 the $pagetitle variable isn't within the scope of your function. If its in the 'more code is above here' you should pass it in as a parameter i.e $sPageTitle = 'a page about something'; function makeimage($pagetitle) { $button = str_replace(' ', '', $pagetitle); header("Content-type: image/jpeg"); $im = @imagecreate(200, 23) or die("Cannot Initialize new GD image stream."); $background_color = imagecolorallocate($im, 0, 57, 122); $text_color = imagecolorallocate($im, 255, 255, 255); imagestring($im, 3, 10, 5, $button, $text_color); $button2 = imagejpeg ($im, $button.".jpeg"); imagedestroy($im); } makeimage($sPageTitle); Link to comment https://forums.phpfreaks.com/topic/64351-image-not-saving-properly/#findComment-320882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.