imagejpeg() not saving jpeg file to server

deftonez4me@cox

New member
Joined
Aug 12, 2008
Messages
2
I am using gd to create a text banner but can't seem to get the file to save after i create it:

<?
// file type
header("Content-type: image/jpeg");

$textFont = "antigoni.ttf";
$header_text_size = 32;
$sub_text_size = 16;
$headertext = "This is a Test Ad!";
$subtext = "And you could have one too!";

// create image
$img = imagecreatetruecolor(728, 90);

//define colors
$gray = imagecolorallocate($img, 157, 158, 162);
$white = imagecolorallocate($img, 255, 255, 255);

// set background color
imagefill($img, 0, 0, $gray);

// Get headerbox info
$header_box = imagettfbbox($header_text_size, 0, $textFont, $headertext);

//Find out the width and height of the header box
$textW = $header_box[2] - $header_box[0];
$textH = $header_box[5] - $header_box[3];

// Calculate the header positions
$positionLeft = (728 - $textW)/2;
$positionTop = ((90 - $textH)/2) - 20;

// Add header text
imagettftext($img, $header_text_size, 0, $positionLeft, $positionTop, $white, $textFont, $headertext);

// Get subbox info
$sub_box = imagettfbbox($sub_text_size, 0, $textFont, $subtext);

//Find out the width and height of the sub box
$textW = $sub_box[2] - $sub_box[0];
$textH = $sub_box[5] - $sub_box[3];

// Calculate the sub box positions
$positionLeft = (728 - $textW)/2;
$positionTop = ((90 - $textH)/2) + 20;

// Add sub text
imagettftext($img, $sub_text_size, 0, $positionLeft, $positionTop, $white, $textFont, $subtext);

//save the image
imagejpeg($img);

?>


This code effectively produces the proper image that i want...but if i change the last line of code to:

imagejpeg($img, 'test.jpg');

it does not save any file, just outputs the name of script:

"http://www.websitename.com/test.php"

What do i need to do to save the fiel to disk?

:confused:
 
What are the permissions on the directory the script is in? The script might not be able to make the file in the folder.
 
Resolved

Thanks. Folder permissions were set to 755, so after changing it to 777, it saves the image fine now. Thanks again!
 
Thanks. Folder permissions were set to 755, so after changing it to 777, it saves the image fine now. Thanks again!
isn't 777 kind of dangerous

and I have the same problem with PNG... my code worked on my other server but not this one..... GD is enabled....... Ideas? chmod 777 didnt work, nor 775
 
Last edited:
Back
Top