Need testers! Imagick windows build.

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Need testers! Imagick windows build.

Post by mkoppanen »

More information can found here:

http://valokuva.org/?p=24
Mikko Koppanen
My blog: http://valokuva.org
Stickboy

Re: Need testers! Imagick windows build.

Post by Stickboy »

Unsure if this is an Imagick bug or an ImageMagick problem or just unhelpful programming, but I thought I'd start with this thread and see if I get anywhere:

Recently I've used the test build of Imagick to thumbnail several tens of thousands of images. A very small percentage of them (around 10 total) produced a corrupt JPEG. This is a little annoying naturally, but the real problem comes later when I try to open the thumbnail again.

If I do this: $im->readimage("TN0711I24N3572.jpg")
I receive:

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'Not a JPEG file: starts with 0x00 0x00 `G:\Scripts\TN0711I24N3572.jpg'' in G:\inetpub\wwwroot\admin\test2.php:8 Stack trace: #0 G:\inetpub\wwwroot\admin\test2.php(8): Imagick->readimage('G:/scripts/TN07...') #1 {main} thrown in G:\inetpub\wwwroot\admin\test2.php on line 8
Which naturally halts the execution of the script. I would have thought that the appropriate behaviour for the readimage function would be to return FALSE - at least that way I could deal it the corrupt image.

Can anyone shed any light?

Thanks
Cully
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Need testers! Imagick windows build.

Post by mkoppanen »

You need to try catch the exception thrown.

Try this:

Code: Select all

$im = new Imagick();
try 
{
  $im->readImage( "broken.jpg" );
} catch ( ImagickException $e ) {
  echo "Caught exception: " . $e->getMessage() . "<br />\n";
}
Mikko Koppanen
My blog: http://valokuva.org
Stickboy

Re: Need testers! Imagick windows build.

Post by Stickboy »

mkoppanen wrote:You need to try catch the exception thrown.

Try this:

Code: Select all

$im = new Imagick();
try 
{
  $im->readImage( "broken.jpg" );
} catch ( ImagickException $e ) {
  echo "Caught exception: " . $e->getMessage() . "<br />\n";
}
Thanks Mikko - that'll certainly get around the problem I have now. Much appreciated.

For the future though, wouldn't returning FALSE rather than throwing an exception make more sense for the readImage function? Given that it returns TRUE on success....

Cully
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Need testers! Imagick windows build.

Post by mkoppanen »

Using the traditional php error handling would lead to something like this:

Code: Select all


/* Can not pass image name to constructor since
  if exceptions are not used it is not possible to catch
  error in construction */
$im = new Imagick();

if ( $im->readImage( "foo.png" ) === FALSE )
{
   /* Do something with the error */
}

if ( $im->thumbnailImage( 200, null ) === FALSE )
{
   /* Do something with the error */
}

if ( $im->writeImage( "th_foo.png" ) === FALSE )
{
   /* Do something with the error */
}

Compared to this:

Code: Select all

try 
{
  $im = new Imagick( "foo.png" );
  $im->thumbnailImage( 200, null );
  $im->writeImage( "th_foo.png" ) 
}
catch ( ImagickException $e )
{
  echo $e->getMessage();
  die();
}
Mikko Koppanen
My blog: http://valokuva.org
Post Reply