note 103657 modified in function.imagecreatefromjpeg by danbrown
| From: | danbrown@php.net | Date: | Tue, 26 Apr 2011 18:52:50 +0000 |
| Subject: | note 103657 modified in function.imagecreatefromjpeg by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179175@lists.php.net to get a copy of this message | ||
I encountered a very strange behaviour:
The background:
Each time users uploaded images, the original file was stored along with a thumbnail and a medium
sized version for small-sized slideshows.
that means that on upload all of these original images were acknowledged by php as valid jpg
The change:
I created a new slideshow script that featured full-screen display. My old "medium-sized"
version were only about 600px wide which caused them to luck all ugly after stretching that to
modern screen sizes.
--> I created a small script that opens all original images and saves bigger
"medium-sized" versions than the once I had.
the problem:
for some reason about 1/3 of all images (not the last third but always the same images) were now
labeled as "... is not a valid JPEG file ..." by php
the cause:
still unknown
the solution:
<?php
...
$src_img = @imagecreatefromjpeg($myJPGfile_relative);
if (!$src_img) {
$src_img = LoadJPEG("http://example.com/".$myJPGfile);
}
?>
Each time the local approach fails the script falls back to loading the same file "from the
outside" via the below mentioned "LoadJPEG" script - big thanks to the author!
That worked even though I'm talking about the exact same file on the exact same server. The
only difference is that one time it's accessed locally and the second via port 80.
when using this, watch for correct paths relative to your script and the possibly different path
relative to your domain.
--was--
I encountered a very strange behaviour:
The background:
Each time users uploaded images, the original file was stored along with a thumbnail and a medium
sized version for small-sized slideshows.
that means that on upload all of these original images were acknowledged by php as valid jpg
The change:
I created a new slideshow script that featured full-screen display. My old "medium-sized"
version were only about 600px wide which caused them to luck all ugly after stretching that to
modern screen sizes.
--> I created a small script that opens all original images and saves bigger
"medium-sized" versions than the once I had.
the problem:
for some reason about 1/3 of all images (not the last third but always the same images) were now
labeled as "... is not a valid JPEG file ..." by php
the cause:
still unknown
the solution:
<?php
...
$src_img = @imagecreatefromjpeg($myJPGfile_relative);
if (!$src_img) {
$src_img = LoadJPEG("http://domain.com/".$myJPGfile);
}
?>
Each time the local approach fails the script falls back to loading the same file "from the
outside" via the below mentioned "LoadJPEG" script - big thanks to the author!
That worked even though I'm talking about the exact same file on the exact same server. The
only difference is that one time it's accessed locally and the second via port 80.
when using this, watch for correct paths relative to your script and the possibly different path
relative to your domain.
http://php.net/manual/en/function.imagecreatefromjpeg.php