PDA

View Full Version : resize jpg image with PHP script.



rray
11-24-2008, 04:03 PM
I am using PHP on a Host Monster web site. The line that causes a "Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 10204 bytes). . ." is:

$src = imagecreatefromjpeg($ImageName);

This works fine on my PC, but not on HostMonster web site.

I have checked that the GD Library is functioning with the print_r(gd_info()) command. It is ok and supports jpeg files.

I have checked that the $ImageName file exists and is correct on Host Monster.

I have copied and pasted other similar scripts and they also bomb on the imagecreatefromjpeg line shown above with same error message.

Any suggestions??



PS: More of the script below.

if ($width >600 || $height>800) {


$src = imagecreatefromjpeg($ImageName); // Create an image so we can do the resize. This is the line that causes the Fatal Error:confused:

$tmp=imagecreatetruecolor($tn_width,$tn_height); // Create a GD-friendly temportary destination image

// this line actually does the image resizing, copying from the original image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$tn_width,$tn _height,$width,$height);

// now write the resized image to disk.
imagejpeg($tmp,$newfilename,100); // 100 is best quality. $newfilename is path for new file.

unlink($ImageName); // deletes extra copied file in ../images dir.
imagedestroy($src);
imagedestroy($tmp);
}

rray
11-25-2008, 01:15 PM
"Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 10204 bytes)..." and line it points line 8 below.



1 <?php // this assumes an image file named a.jpg resided in the same directory that this php script runs.
2 // width of a.jpg is 2551, height is 3299.
3
4 // Content type
5 header('Content-type: image/jpeg');
6
7 $thumb = imagecreate(600,800);
8 $source = imagecreatefromjpeg("a.jpg");
9
10 //Resize
11 imagecopyresized($thumb,$source, 0, 0, 0, 0, 600, 800, 2551, 3299);
12
13 //Output
14 imagejpeg($thumb,"newfile1.jpg");
15 ?>

rray
11-25-2008, 06:27 PM
The following two links has the answer.

http://forums.devshed.com/php-development-5/imagecreatefromjpeg-crashing-433330.html?&highlight=Fatal+Error

http://au.php.net/imagecreatefromjpeg :)