another one for the php heads: weirdness and the gd library (1 Viewer)

  • Thread starter plug
  • Start date
  • Replies 7
  • Views 867
  • Watchers 0

plug

Well-Known Member
Joined
Feb 11, 2003
Messages
6,046
Location
dublin/cork
Website
www.outonalimbrecords.com
this is probably more to do with the server on which this script is running that the script itself, as I developed and tested it locally without problems... anyway it's wrecking my head something stupid.

I created a couple of classes to handle the validation, upload and resize of images.

the validator works fine; it takes a _FILES array and validates a few things including the mime type of the image. all valid images are added to an array that gets passed to an uploader.

the uploader is grand as well; it accepts the array of valid images, creates a folder (and a database entry for that folder) and uploads the image files from the temp dir to the newly created dir. all fine here too.

resizing... here's where the problem occurs. but only and a specific point and under certain conditions. say the image is a jpeg (already fully validated)... the problem will occur when using the function imagecreatefromjpeg(), which accepts a reference to an image and returns an image identifier, which can then be used for resizing etc. I need to put a try/catch block here but anyway, this is where my script fails, but ONLY (based on some testing) if the physical file dimensions are over 2000x1500. it seems to have nothing to do with filesize, although I'm not positive yet. as I mentioned before, this is only happening on the server that I've uploaded to, not the local version which seems to accept all sizes without issue. I'm going to run a test on a different server as well, just to see what's going on. I must try and see what version of the gd library they're running on the server too.

the problem with this is, I need this script to be able to handle large images. so this isn't good news. has anyone any ideas, or have they come across this kind of thing before?????
 
I've done a bit of reading around on this and I'm beginning to settle on the possibilty that it's probably either to do with the php.ini settings, (either or a combo of memory_limit and max_execution_time), and/or whether or not the server has the actual balls to do the work involved. a busy evening of testing and more testing lies ahead...
 
Do you get an error or is it just failing silently? If so does the error have a message?
 
I got this info from php.net

The memory required to load an image using imagecreatefromjpeg() is a function
of the image's dimensions and the images's bit depth, multipled by an overhead.
It can calculated from this formula:
Num bytes = Width * Height * Bytes per pixel * Overhead fudge factor
Where Bytes per pixel = Bit depth/8, or Bits per channel * Num channels / 8.

Did you try increasing the memory limit in your script?

Code:
ini_set("memory_limit", "50M");
 
hi bladez! I'm failing silently. I think error checking is suppressed on the server Im using. I think. I'm not too well up on my error checking to be honest... :eek: how do I turn on error checking actually, seeing an error might help a lot. what's not helping is the server; it's fucking crawwwwling. but it's only a test server, so I have to go into the guy I'm working with on this tomorrow and see if there are any issue on the main server. I really, really think it's a server issue at this stage. I've used ini_set to give the script some breathing space by increasing memory_limit and max_execution_time. this seemed to help at first but it hasn't really in actuality. well it's hard to tell because the server is acting the bollix.

basically, the files are hanging, then crashing out but ONLY above a certain size. I mean size as in dimensions, as opposed to filesize. filesize doesn't seem to matter at all. I did read something which makes me really suspicious of the server... in fact I'm 99% convinced this is the problem. apparently when an image file is opened by a gd function such as imagecreatefromjpeg, it has to store every pixel of the image in memory to create a raw, uncompressed snapshot of the image, which can mean a LOT of memory usage with a large image. if the server doesn't have sufficient ram, then fssssssssssss...... faaack.

sounds suspiciously like my problem. I could be wrong though. very, very wrong. :)
 
You can display errors by overriding the php.ini settings.

Code:
error_reporting(E_ALL);
ini_set("display_errors", 1);

About the problem - I agree. Its probably, like you say, the server not being able to allocate enough memory for the operation.
 

Users who are viewing this thread

Activity
So far there's no one here
Old Thread: Hello . There have been no replies in this thread for 365 days.
Content in this thread may no longer be relevant.
Perhaps it would be better to start a new thread instead.

21 Day Calendar

Lau (Unplugged)
The Sugar Club
8 Leeson Street Lower, Saint Kevin's, Dublin 2, D02 ET97, Ireland

Support thumped.com

Support thumped.com and upgrade your account

Upgrade your account now to disable all ads...

Upgrade now

Latest threads

Latest Activity

Loading…
Back
Top