Page 1 of 1

IM working from command line not from PHP

Posted: 2008-11-04T16:44:48-07:00
by pststerrye
I've read some very lengthy posts here about this, but still cannot call IM from a PHP file. Here's what I know:
----------------------------
From command line:

convert -version
Version: ImageMagick 6.2.0 07/10/05 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2005 ImageMagick Studio LLC

type convert
convert is hashed (/usr/bin/convert)

According to my admin guys, the following works fine:

/usr/local/bin/convert page1.jpg output.gif

---------------------------
From PHP, the screen is blank, the file isn't converted, and the error in the log is:

sh: line 1: /convert: No such file or directory

-----------------------------
If I run this:
$env_vars = explode( ':', $HTTP_ENV_VARS['PATH']);
$path = $env_vars[1]."/convert";
echo $path;

I get this:
/usr/sbin/convert

If I run this:
echo $HTTP_ENV_VARS['PATH'];

I get this:
/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
--------------------------------
I have tried all of the following, and none work:

system("convert I-70Scout.jpg THscout.gif");
system("/usr/bin/convert I-70Scout.jpg THscout.gif");
system("/usr/bin/local/convert I-70Scout.jpg THscout.gif");
system("/usr/sbin/local/convert I-70Scout.jpg THscout.gif");
system("/usr/sbin/convert I-70Scout.jpg THscout.gif");
---------------------
If I run this using any of the above paths and no paths:
$array=array();
echo "<pre>";
exec("/usr/bin/convert I-70Scout.jpg 41.png 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";

I get:
Array
(
)

1
--------------------------
I've tried using the this with variations of the path, but it didn't work either:
system("PATH=\$PATH:/usr/sbin/ && convert 'page1.pdf[0]' 'abcde.jpg' 2>&1");

-------------------------
Does anybody have any other ideas?

I am running PHP 4.3 - could that be the problem?

Thanks in advance for any help you can give me -

Re: IM working from command line not from PHP

Posted: 2008-11-04T16:55:12-07:00
by anthony
The fact that you get "/convert" instead of "/usr/bin/convert" means that the command path is still not correct!

Also check what directory you are running the command in. That is try running a 'ls' command and see if PHP can see the image files you are trying to read.

finally also check what the PHP process is running as (run a 'id' command). The PHP may be running as 'nobody' or 'apache' rather than as you. And also that the directory is both read and writable by that user.

Basically check everything that you are needing. It is probably something rather simple.

Re: IM working from command line not from PHP

Posted: 2008-11-13T17:38:03-07:00
by pststerrye
Thanks for your response - it did turn out to be something simple - something in the safe mode settings. I do have to use the exact path, but otherwise everything works great! :D

Re: IM working from command line not from PHP

Posted: 2008-11-13T17:57:07-07:00
by fmw42
I am no PHP expert, but recently tried to see if I could even find IM via my hosting provider. So first be sure you know the path to IM. On my server (after contacting them and spending quite some effort to figure out how to do anything), I was finally able to just see what IM version was being used. So I was able to do any one of the following:

<?php
system("/usr/local/bin/convert -version");
?>

returned:
Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC


<?php
$IM_version=shell_exec("/usr/local/bin/convert -version");
echo $IM_version
?>

returned:
Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

returned:
Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org

Try your paths to IM in the above and see if any of them give you something like was returned above. Looks like my hosting provider is using a rather old version of IM.

The user Bonzo may be able to help further. You can also look on his web site as he has a lot of IM examples and pointers/tidbits about using PHP. See http://www.rubblewebs.co.uk/