By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,222 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,222 IT Pros & Developers. It's quick & easy.

imagecreatefromjpeg() and large images

P: n/a
jn
This is the weirdest thing I've come across in a while.

I'm trying to resize an image. If I give it a small image ( < 100K) it will
resize. If I give it a larger image, it gives me the IE "Action Cancelled"
page. The memory_limit for PHP has been changed to 30MB so that's not the
problem. I know that the line with imagecreatefromjpeg() is the problem
(even though I can't get an error message).

I can run this code with the large images on my Windows machine and on my
other Linux server. There are no syntax errors.

When it works, the output is:
THE ORIGINAL FILE EXISTS
RESIZED
THE THUMBNAIL FILE EXISTS

The PHPInfo
http://www.williamscompany.com/newsite/phpinfo.php

Here's the code for the test page:
http://www.williamscompany.com/newsite/testing.php

<?
function resize_image($file_name_src, $file_name_dest, $weight, $height='',
$quality=70)
{
if (file_exists($file_name_src) && isset($file_name_dest))
{
$est_src = pathinfo(strtolower($file_name_src));
$est_dest = pathinfo(strtolower($file_name_dest));
$size = getimagesize($file_name_src);
if($weight != ''){
$w = number_format($weight, 0, ',', '');
$h = number_format(($size[1]/$size[0])*$weight,0,',','');
}

if($height != ''){
$h = number_format($height, 0, ',', '');
$w = number_format(($size[0]/$size[1])*$height,0,',','');
}

$file_name_dest = substr_replace($file_name_dest, 'jpg', -3);
$dest = imagecreatetruecolor($w, $h);

$src = imagecreatefromjpeg($file_name_src);

imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);

imagejpeg($dest,$file_name_dest, $quality);

return TRUE;
}
return FALSE;
}

$image = './admin/1.jpg';
$thumb = './admin/1_t.jpg';

if(file_exists($image)){
echo "THE ORIGINAL FILE EXISTS<br>";
} else {
echo "ORIGINAL DOES NOT EXIST<br>";
}

if(resize_image($image, $thumb, 60 ) == TRUE){
echo "RESIZED<br>";
} else {
echo "NOT RESIZED<br>";
}

if(file_exists($thumb)){
echo "THE THUMBNAIL FILE EXISTS<br>";
} else {
echo "THUMBNAIL DOES NOT EXIST<br>";
}
?>
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 17 Feb 2004 02:23:12 GMT, "jn"
<us********************************@jasonnorris.ne t> wrote:
This is the weirdest thing I've come across in a while.

I'm trying to resize an image. If I give it a small image ( < 100K) it will
resize. If I give it a larger image, it gives me the IE "Action Cancelled"
page. The memory_limit for PHP has been changed to 30MB so that's not the
problem. I know that the line with imagecreatefromjpeg() is the problem
(even though I can't get an error message).


Can you give a link to an example JPEG >100k that fails?

(It's relatively easy to construct a 100k JPEG that would consume 30M of
memory when loaded into GD - so don't rule out memory limits?)

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #2

P: n/a
jn
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:n0********************************@4ax.com...
On Tue, 17 Feb 2004 02:23:12 GMT, "jn"
<us********************************@jasonnorris.ne t> wrote:
This is the weirdest thing I've come across in a while.

I'm trying to resize an image. If I give it a small image ( < 100K) it willresize. If I give it a larger image, it gives me the IE "Action Cancelled"page. The memory_limit for PHP has been changed to 30MB so that's not the
problem. I know that the line with imagecreatefromjpeg() is the problem
(even though I can't get an error message).


Can you give a link to an example JPEG >100k that fails?

(It's relatively easy to construct a 100k JPEG that would consume 30M of
memory when loaded into GD - so don't rule out memory limits?)

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>


The other 2 server do this just fine. The servers that work only have the
default 8M of memory allocated and it resizes the image.

This is the image:
http://williamscompany.com/newsite/1.jpg

The test script as before
http://williamscompany.com/newsite/testing.php

The phpinfo of the server that doesn't work (PHP 4.3.2, GD 2.0.15)
http://williamscompany.com/newsite/phpinfo.php

The phpinfo of the server that does (PHP 4.3.0, GD 2.0)
http://buyhomestoday.net/newsite/phpinfo.php
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.