Page 1 of 1

Problem with simple use of Perl Magick - Server Issue?

Posted: 2009-02-09T03:34:03-07:00
by HorrorRoom
As requested (via PM from ‘Magick’) I am re-posting my question about the use of Image Magick in Perl. This problem is currently holding up a large community project. ‘Magick’, many thanks for taking a few seconds to give me an answer as promised, much appreciated! :)

I have given my host a link to this post so hopefully they will be able to read up on the issue and seek a resolution.

The problem here is that the 'READ' function of Imagemagick doesn’t seem to work for some reason.
My host says that Image Magick is running on the server and that I should have no problems.
If you could confirm that the code below should work on a server that has
Image Magick running it will at least eliminate the possibility that I am at fault.

This code is the minimum required to show my point. It should read an image in and write it out again. Unfortunately it doesn’t work.

Code: Select all

#!/usr/bin/perl
use CGI;
use CGI::Carp  qw ( fatalsToBrowser );
use File::Basename;
use CGI qw(:all);

use Image::Magick;

print header;

my $src = Image::Magick->new;

$src->Read("../../source.png");
$src->Write("../../updated.png");

undef $src;

print q(Complete);
exit;
When running this code I receive the following error:
--------------------------------------------------
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@host.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
--------------------------------------------------

If I comment out the 'READ' line the script runs through and prints 'Complete' to the screen but no file is written out.

My host suggested that I try changing the READ line to: $src->Read(-"../../source.png"); which does let the script run to completion, but no image is actually processed\loaded. So while it allows the script to run it doesn’t fix anything :(


If it's any use I to know, I have ftp access and limited cPanel access to my webspace\account but do not have any other direct server access of any kind and cannot run shell commands.

If there is anything my host should be aware of that would resolve this issue I would be extremely grateful if you'd let me know so I can pass on the info. They do currently assume that they support Image Magick even though I can't get it working.

Kind regards, and many thanks for your help.

Re: Problem with simple use of Perl Magick - Server Issue?

Posted: 2009-02-09T07:28:05-07:00
by magick
All methods should look for exceptions which will give you promising leads if there is a problem. Use
  • $x = $src->Read("../../source.png");
    warn "$x" if "$x";
And the reason for any failure will be displayed and certainly will help you with debugging.

It would be helpful to ensure the script runs from the command line. If its from a web script, be sure to post the HTTP headers first otherwise the web server will return exceptions like you are seeing. We typically post the HTTP headers and then display debugging information like this:
  • print "<pre>$x</pre>\n";
That way any exceptions should up right on the web page. When the page is debugged and ready to go live, we remove the debugging statements.

Re: Problem with simple use of Perl Magick - Server Issue?

Posted: 2009-02-09T08:05:29-07:00
by HorrorRoom
Many thanks. I've updated my script to include your code and I've passed the info on to my host (as included below) as there isn’t much progress yet. I apologise at my lack of expertise and your help here is greatly appreciated!

Here is my message to my host and the updated script code just for your information:
-------------------------------------------------------------------------------
...What happens is no different, it still displays the 'Internal Server Error' message. Unless I change the line $x = $src->Read("../../source.png"); to $x = $src->Read(-"../../source.png"); whereby it doesn't actually read in the file but it does run and give the error message:

Exception 435: unable to open image `0': No such file or directory.

Though it runs with the '-' added to the line it isn't a solution as it renders the read operation useless.
The image does indeed exist correctly at the stated path and is displayed okay at the bottom of the page using the same path and filename.

Code: Select all

#!/usr/bin/perl
use CGI;
use CGI::Carp  qw ( fatalsToBrowser );
use File::Basename;
use CGI qw(:all);
use Image::Magick;
print header;

my $src = Image::Magick->new;

$x = $src->Read("../../source.png");
warn "$x" if "$x";

print "<pre>$x</pre>\n";

$src->Write("../../updated.png");
undef $src;
print q(<br><br><img src="../../source.png"><br>../../source.png);
exit;
-------------------------------------------------------------------------------

Re: Problem with simple use of Perl Magick - Server Issue?

Posted: 2009-02-09T08:09:44-07:00
by magick
Try running your script from the command line and see if it can read your file. Also ensure PNG is supported in your version of ImageMagick. Type
  • convert -list format
and look for the PNG tag.