ImageMagick not working, and not giving error messages either
I have some Perl code I wrote for a client which, in part, resizes images using ImageMagick's convert
.
This was done via backticks, capturing the output in this way:
$output = `convert foo.jpg foo.gif 2>&1`; # simplified example
Recently my client's hosting company made what he was told were "DNS changes", and since that date*, the command doesn't work, and not only that, there's no $output either.
Assuming something has happened like him being moved to a server which hasn't got ImageMagick, or a botched install or update of the library -- shouldn't I be getting something back from that? At least a "convert not found"? I've tried with system() as well and it's the same. Image not converted, nothing comes back.
Unfortunately, command-line access is not available.
* 开发者_StackOverflowI suppose this could actually be a coincidence.
You can use convert's debug option to find out what it's doing.
To capture all outputs of a shell command use Capture::Tiny like this:
use Capture::Tiny 'capture';
my @command = qw( convert foo.jpg foo.gif );
my $return_code;
my ($stdout, $stderr) = capture {
$return_code = system( @command );
};
$stdout
and $stderr
will contain what it says on the tin. $return_code
will return the return code of the task itself, which is traditionally 0 when successful or a non-zero numerical value when an error happened.
They may have no shell installed (think of perl/mod_perl being run in a chroot), such that backticks cannot be executed at all (since they involve calling sh -c 'convert ...'
. Always check $?
and $!
.
精彩评论