0

I have a file upload class which returns an image resize object if the file upload is believed to be an image. The construct of the image resize class starts with this:

$this->resource = imagecreatefromstring($this->getData());

if (!is_resource($this->resource)) {
  return $this->error(IMAGE_ERR_SOURCE_CREATION_ERROR);
}

$this->getData() returns the string returned from file_get_contents from tmp_name from $_FILES[..] array.

The promlem is as follows. It works perfectly fine on my development server 5.3.0 but imagecreatefromstring() fails on the production server, 5.3.5.

Why? I cannot get my head around it, I have compared strings of images from development and product using base64 and they are identical. What do I need to look at thats changed from .0 to .5?

Edit: Yes, GD2 is installed and working correctly. Incidentally, WordPress (3.1) is also installed on this server and all image functionality is working correctly, which is also why I am so puzzled.

Edit 2

After debugging with display_errors (I know should have done this first), the error returned is:

Warning: imagecreatefromstring(): No JPEG support in this PHP build

Does this mean I have to reinstall GD with JPEG support or can it be enabled once installed, IE now?

5
  • 1
    Does the PHP installation actually have support for the image format you're trying to use? Check phpinfo for the supported codecs. Commented Mar 30, 2011 at 10:00
  • Can you define "fails" more precisely for us? What image format is the data? Commented Mar 30, 2011 at 10:02
  • run this code $handle = fopen('img.jpg', 'r'); $contents = fread($handle, filesize('img.jpg')); $image = imagecreatefromstring($contents); header("Content-type: image/jpeg"); imagejpeg($image); fclose($handle); Commented Mar 30, 2011 at 10:06
  • and Test if this function is working or not. Commented Mar 30, 2011 at 10:07
  • I wish I could.. It just returns false, no errors at all. The function just returns false.. Commented Mar 30, 2011 at 10:12

1 Answer 1

2
  1. Ensure you do have GD on the production server (using <?php phpinfo(); ?> or $> php -m) and that is configured correctly (using $> php --re GD and $> php --ri GD).
  2. Enable display errors on production server (temporally)
  3. If [2] fails, use error_reporting(E_ALL)
  4. Run script testcase through SSH on production server and see if it fails as well (it should)
  5. Using [4], run it through strace (if on linux) or TraceNT (on windows) and see where the error started out from.
Sign up to request clarification or add additional context in comments.

8 Comments

Ahhhhh. I may have used error_reporting(E_ALL); but not display_errors. Massive fail on my part... See question for update.
If you can't get it to write anything (check logs as well) you'll have to try my 4/5 methods. Strace is quite powerful, though I'm afraid you need someone quite knowledgeable in linux (me excluded).
Well, the error is pretty self-explanatory. Mission accomplished. :). With regards to your last question, I'm not sure, it depends on the build. In my case, I could just replace the GD library, but I'm not sure about yours. I suppose you could back up your GD copy and throw in a new one.
Well, you can upload exe files if you wanted to, PHP won't complain ;). Did you tried resizing them (from WP)? WP is clever, it might have some fail overs - such as resizing by HTML/CSS if it failed via PHP.
@Matt WordPress has a lot of fairly smart code for falling back to dumber behaviour if the PHP version it's running on lacks support for certain image functions (see WordPress's wp-includes/media.php code.) It's perfectly possible to upload images, just as files, without GD support for JPEG; WordPress is probably just coping as best it can after that point (it might, say, be displaying full-size images with the display sizes set to thumbnail size on your page, instead of rescaling to generate real thumbnails, for example.)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.