Page 1 of 1

Weirdness killing script

Posted: Fri Nov 12, 2004 2:57 am
by mchaggis
Hi,

I have a wierdness that is baffling me.

Code: Select all

<?php

print "Before";
$img = imagecreatefromjpeg ( $filename );
print "After";
?>
$filename is a 600k jpeg file.

Now executing the above does nothing, zip, nada. It should just print the words Before and After, but what appears to be happening is the script just dies and nothing is printed, if I place exit after the first print, then the script actually runs and just prints Before.


I have seen this before with some other code, that I am just using readfile() or passthru() of various file formats and sizes. I just put it down to the files being corrupted during uploading, but this doesn't actually seem to be the case?

Very confused. :?

Posted: Fri Nov 12, 2004 3:09 am
by mchaggis
Ok, a little more investigation and i find the following... doh!
cs at kainaw dot com
01-Nov-2004 07:09
The ImageCreateFromJPEG() function is capable of throwing an emalloc() error. If this happens, the script will die, but the error will be in your error logs. You should ensure that you have memory available before creating a large image from a jpeg file.
If I edit the php.ini file entry for:

Code: Select all

memory_limit
It now works, but I can't see how a 600k images is requiring so much memory???

Re: Weirdness killing script

Posted: Fri Nov 12, 2004 3:13 am
by phpScott
mchaggis wrote:Hi,

Code: Select all

<?php

print "Before";
$img = imagecreatefromjpeg ( $filename );
print "After";
?>
i would suggest doing a if(file_exists($filename)) before loading the file as it may be crashing because the file doesn't exist where you think it should be.
second thing is to check to make sure that you have the GD2 library loaded and in the right place.
thirdly is your display_errors on in your php.ini file? As hopefully you are getting some sort of error message

[edit]
ignore me then
[/edit]

Posted: Sat Nov 13, 2004 7:16 am
by djot
-
Hi,
It now works, but I can't see how a 600k images is requiring so much memory???
To work with the .jpg file, it will have to be uncompressed. That would be approximately 25MB or even more php has to work with - and memory limit is 8MB by default.

djot
-