Jump to content

Image not saving properly???


cturner

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.