Problem With imagecreatefromjpeg

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
912bliss
Forum Newbie
Posts: 6
Joined: Wed Jul 14, 2010 4:53 am

Problem With imagecreatefromjpeg

Post by 912bliss »

Hi
The following code works on my computer but when i load it onto the server it works until it gets to imagecreatefromjpeg line then the program stops , the folders are all 0777
What i am trying to do is to scan through a folder and resize all images in that folder and move the resized images to a different folder

Any Idea what the problem could be

<?php

$dir = 'test';

$files2 = scandir($dir, 1);
$count=count($files2)-2;
for($i=0; $i<$count;$i++)
{

$uploadedfile ="test/".$files2[$i];

$resizedfile="pic/".$files2[$i];


list($width,$height)=getimagesize($uploadedfile);
$newwidth=330;
$newheight=($height/$width)*280;
if(($height/$width)<1.3){$newheight=($height/$width)*340;}
$tmp=imagecreatetruecolor($newwidth,$newheight);

$src =imagecreatefromjpeg($uploadedfile);


imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);



imagejpeg($tmp,$resizedfile,90);

}

?>
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: Problem With imagecreatefromjpeg

Post by Gargoyle »

is the gd library available on the machine in question?
912bliss
Forum Newbie
Posts: 6
Joined: Wed Jul 14, 2010 4:53 am

Re: Problem With imagecreatefromjpeg

Post by 912bliss »

I was getting the following error ,
Allowed memory size of 52428800 bytes exhausted (tried to allocate 12800 bytes) in createimage.php on line 48

i increase the memory limit from 24m to 50 m but still the same error , then increased it to 100m and it worked .

Why does imagecreatefromjpeg use that amount of memory just for an 240K image

Thanks for the help
Post Reply