Page 1 of 1

Need testers! Imagick windows build.

Posted: 2007-10-03T12:02:45-07:00
by mkoppanen
More information can found here:

http://valokuva.org/?p=24

Re: Need testers! Imagick windows build.

Posted: 2007-11-02T19:43:18-07:00
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

Re: Need testers! Imagick windows build.

Posted: 2007-11-03T07:05:18-07:00
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";
}

Re: Need testers! Imagick windows build.

Posted: 2007-11-05T14:36:28-07:00
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

Re: Need testers! Imagick windows build.

Posted: 2007-11-06T01:04:29-07:00
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();
}