Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I am using Imagemagick to manipulate some images but get duds occassionally and get the message:

"Exception 410: no images to mogrify (Composite) at libraryimagetest.cgi line 77."
What I want is to avoid the error message and redirect to another page, eg:
$background->Composite(image=>$logo,compose=>'over',gravity=>@serverar +r[5]) || &redirect;

how do I avoid the error message and get the redirect to work?

Replies are listed 'Best First'.
Re: avoiding error message
by Corion (Patriarch) on Oct 23, 2003 at 10:36 UTC

    I'm not sure where the error stems from, but I guess that some diagnostics will help you, together with an eval block that will catch the program when ImageMagick dies:

    warn 'The \$background ImageMagick object was not defined.' unless $background; warn "The file '$logo' was not found" unless -f $logo; eval { $background->Composite(image=>$logo,compose=>'over',gravity=>$server +arr[5]); }; if ($@) { warn "ImageMagick composite returned the following error: $@"; warn "image => '$logo',compose=>'over',gravity=>'$serverarr[5]'"; redirect(); };

    You will find the diagnostics in your webserver error log.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: avoiding error message
by skx (Parson) on Oct 23, 2003 at 11:11 UTC

     The real solution to this problem I'm sure is to fix your code to test errors and handle things gracefully.

     But if you want to do the redirect on error you could do this by catching "warn" and "die" errors - and doing the redirect there.

    Steve
    ---
    steve.org.uk
Re: avoiding error message
by vek (Prior) on Oct 24, 2003 at 02:25 UTC

    Are you sure you want that array slice there? Perhaps @serverarr[5] should really be $serverarr[5]?

    -- vek --