Problems with scaleImage
Problems with scaleImage
I wrote many years ago a script we use to display images pulled from a directory structure. This script also resizes to what we call detail image and thumb nail from the full size image. The imagick module used was 0.9.x.
Trying to rebuild servers with more modern OS versions like EL5 or EL6, I get all kind of issues, so I tried to upgrade imagick to a current version (last try today with version 3.0.1). Due to the API changes I rewrote part of my script. One of the functions we use is scaleImage. And here is where the problem starts. Many of our images are 640x480 or 800x600, but we also have all kind of other sizes. The function gets used to resize to 210x158 or 100x75. And on many of the images all I get is 10 bytes (JPEG header for example) but nothing else. No error anywhere.
How can I try to debug this?
Trying to rebuild servers with more modern OS versions like EL5 or EL6, I get all kind of issues, so I tried to upgrade imagick to a current version (last try today with version 3.0.1). Due to the API changes I rewrote part of my script. One of the functions we use is scaleImage. And here is where the problem starts. Many of our images are 640x480 or 800x600, but we also have all kind of other sizes. The function gets used to resize to 210x158 or 100x75. And on many of the images all I get is 10 bytes (JPEG header for example) but nothing else. No error anywhere.
How can I try to debug this?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Problems with scaleImage
Have you reviewed this page: http://us3.php.net/manual/en/function.i ... eimage.php
Perhaps you should post your code or at least that part of the code? Also what version of IM are you using?
Perhaps you should post your code or at least that part of the code? Also what version of IM are you using?
Re: Problems with scaleImage
The code is pretty simple:
The version of ImageMagick is 6.2.8.0-4.el5_1.1
The output sometimes is 10 bytes only for a JPEG image, but sometimes it works. I have images where resizing to 100x75 works, but not to 210x158, some the 210x158 works but the 100x75 doesn't, some images doesn't work for either sizes, some it works both. Nothing is in the Apache error log.
Code: Select all
$imghandle = new Imagick();
if (!$imghandle->readImage($pathimage)) {
error_log("ImageRead: Failed to read image");
exit;
}
if (!$imghandle->scaleImage($resize_x, $resize_y)) {
error_log("ImageScale(".$image."): scaling image failed");
exit;
}
$image_data = $imghandle->getImageBlob();
header("Content-Length: ".strlen(image_data));
print $image_data;
The output sometimes is 10 bytes only for a JPEG image, but sometimes it works. I have images where resizing to 100x75 works, but not to 210x158, some the 210x158 works but the 100x75 doesn't, some images doesn't work for either sizes, some it works both. Nothing is in the Apache error log.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Problems with scaleImage
That is extremely old. But then you need an old version for IMagick which does not seem to be in active development.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Problems with scaleImage
The PECL version which was installed is 3.0.1, which is the current version. ImageMagick is the available version for EL5.
The old server was using older version of the PECL module (< 1.0) and the EL4 version of ImageMagick.
The old server was using older version of the PECL module (< 1.0) and the EL4 version of ImageMagick.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Problems with scaleImage
Some IMagick functions, such as distortImage, require IM 6.3.6 or higher.
I would suggest you try creating the simplest script possible with fixed number arguments (not variables) for scaleImage and test that.
I would suggest you try creating the simplest script possible with fixed number arguments (not variables) for scaleImage and test that.
Re: Problems with scaleImage
Post a link to an image that isn't working for you for us to test. I don't think this will help but you don't have a content header:
header('Content-Type: image/jpeg');
header('Content-Type: image/jpeg');
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
Re: Problems with scaleImage
So I installed another server, this one with EL6, which comes with ImageMagick 6.5.4.7-5.el6. The php version is 5.3.6 (own build) and Apache is 2.2.19 (own build). PECL imagick module is 3.0.1
Same problems: Some images work fine in both resizes, some only of them works, some none work.
Same problems: Some images work fine in both resizes, some only of them works, some none work.
Re: Problems with scaleImage
I do, I just didn't post that part of the script. The total script is longer, as it has to calculate where on the disk it is, potential fetch it via http or generate a white image if the file doesn't exist.DJ Mike wrote:Post a link to an image that isn't working for you for us to test. I don't think this will help but you don't have a content header:
header('Content-Type: image/jpeg');
Here is one example from our current working server based on EL4, ImageMagick 6.0.7-1-17, Apache 2.0.x, imagick 0.9.11.
http://img.autc.com/display.php?img=169 ... 218993.jpg
http://img.autc.com/display.php?img=169 ... 993_dt.jpg
http://img.autc.com/display.php?img=169 ... 993_th.jpg
The above image works as full size (which just gets passed through) and as _th but not as _dt. The servers I am working on are not exposed to the Internet.
*edit* Ok, I exposed one of the servers to the Internet and put a sample of images up at: http://imgarchive.autc.com/test/
Re: Problems with scaleImage
The images you posted above the edit look OK but from http://imgarchive.autc.com/test/ I got http://imgarchive.autc.com/display.php? ... 275_dt.jpg which shows me an error message:*edit* Ok, I exposed one of the servers to the Internet and put a sample of images up at: http://imgarchive.autc.com/test/
The image “http://imgarchive.autc.com/display.php? ... 275_dt.jpg” cannot be displayed because it contains errors.
I saw that a lot on I project last week. If you comment out the image header the output will be text and should give you the PHP error message. If not you have to enable error reporting.
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
Re: Problems with scaleImage
I copied one of your images that didn't work for you and tested using only scaleImage() with the sizes 100x75 and 210x158. Both worked. Looks like the error is before scaleImage().
http://eclecticdjs.com/mike/temp/11/07/ ... 890275.php
http://eclecticdjs.com/mike/temp/11/07/ ... 890275.php
Code: Select all
<?php
$file = "10571930_74890275.png";
$image = new Imagick();
$image->readimage($file);
$image->scaleImage(210, 158);
header("Content-Type: image/png");
echo $image;
?>
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
Re: Problems with scaleImage
It can not be displayed because it is a corrupt image. All the server is sending is 10 byte (the start of a jpeg file). And the code for this is still:DJ Mike wrote:The images you posted above the edit look OK but from http://imgarchive.autc.com/test/ I got http://imgarchive.autc.com/display.php? ... 275_dt.jpg which shows me an error message:*edit* Ok, I exposed one of the servers to the Internet and put a sample of images up at: http://imgarchive.autc.com/test/
The image “http://imgarchive.autc.com/display.php? ... 275_dt.jpg” cannot be displayed because it contains errors.
I saw that a lot on I project last week. If you comment out the image header the output will be text and should give you the PHP error message. If not you have to enable error reporting.
Code: Select all
$imghandle = new Imagick();
if (!$imghandle->readImage($pathimage)) {
error_log("ImageRead: Failed to read image");
exit;
}
if (!$imghandle->scaleImage($resize_x, $resize_y)) {
error_log("ImageScale(".$image."): scaling image failed");
exit;
}
$image_data = $imghandle->getImageBlob();
header("Content-Length: ".strlen(image_data));
print $image_data;
Re: Problems with scaleImage
Ok, I grabbed this particular image "10571930_74890275.jpg". Running from a command line the following code:DJ Mike wrote:I copied one of your images that didn't work for you and tested using only scaleImage() with the sizes 100x75 and 210x158. Both worked. Looks like the error is before scaleImage().
http://eclecticdjs.com/mike/temp/11/07/ ... 890275.php
Code: Select all
<?php $file = "10571930_74890275.png"; $image = new Imagick(); $image->readimage($file); $image->scaleImage(210, 158); header("Content-Type: image/png"); echo $image; ?>
Code: Select all
<?php
$file = "10571930_74890275.jpg";
$image = new Imagick();
$image->readimage($file);
$image->scaleImage(210, 158);
echo $image;
?>
Code: Select all
<?php
$file = "10571930_74890275.jpg";
$image = new Imagick();
$image->readimage($file);
$image->scaleImage(210, 158);
$image_data = $image->getImageBlob();
echo $image_data;
?>
Code: Select all
$ hexdump -C 10571930_74890275_dt_current_code.jpg
00000000 ff d8 ff e0 00 10 4a 46 49 46 |ÿØÿà..JFIF|
0000000a
Re: Problems with scaleImage
gshumway wrote: It can not be displayed because it is a corrupt image. All the server is sending is 10 byte (the start of a jpeg file). And the code for this is still:
Code: Select all
$imghandle = new Imagick(); if (!$imghandle->readImage($pathimage)) { error_log("ImageRead: Failed to read image"); exit; } if (!$imghandle->scaleImage($resize_x, $resize_y)) { error_log("ImageScale(".$image."): scaling image failed"); exit; } $image_data = $imghandle->getImageBlob(); header("Content-Length: ".strlen(image_data)); print $image_data; [/quote] Ok, found one error, the line "header("Content-Length: ".strlen(image_data));" is missing the $ in front of image_data. Fixing that I do get the correct size returned for image "10571930_74890275.jpg" when requested as _dt (210x175) and it works from command line (Perl-GET 'http://imgarchive.autc.com/display.php?img=10571930_74890275_dt.jpg' > 10571930_74890275_dt_fixed_strlen.jpg), although the size of the file is less (23,950 instead of 23,972). Checking more images now.
Re: Problems with scaleImage
All images I tested are now working, so I think that the problem was the missing $. Good. Now I can rebuild the second server also with EL6