views:

644

answers:

1

I am rather new to using the command line and php. That being said I have been trying to figure out how to use ImageMagick with the exec() function. I have this currently,

$command="/usr/local/lib/ImageMagick  convert images/a.pdf images/a.png"; 

if(exec($command)){
    echo 'yes';
}
else{
    echo 'no';
}

Which is returning 'no'. I believe I am missing something about how to execute convert from the correct directory. Is my $command set up properly? (I was given the path to ImageMagick from my web host, Lunarpages).

I have read through some of the other questions regarding ImageMagick but I haven't found much to help me set up my command.

Thanks for any help,
Levi

+3  A: 

What your command is currently attempting to do is execute a program named /usr/local/lib/ImageMagick which I am guessing is not what you were intending. If that is the path to ImageMagick and you want to use the convert utility you need to modify your command to the following:

/usr/local/lib/ImageMagick/convert images/a.pdf images/a.png

At which point it should work without any issues! You may want to dig further into what the convert command can do for you!

X-Istence
I tried this and I am still getting the error, I tried adding/removing forward slashes for paths to filenames such as 'images/a.pdf' to '/images/a.pdf'. It didn't work for me but do you think the paths could be read incorrectly?
Levi
Try adding a PHP diagnostic output `echo getcwd();` command to show the current working directory. Perhaps when `exec()` runs the working directory is not as expected (just above `images`).
wallyk
I am indeed in the correct spot, just above images (in /gallery/). However if I am just above images will exec() try and run from /gallery/usr/local/lib/ImageMagick/convert ? Or will exec() work from the root?
Levi
When you run exec() it will run in whatever the current working directory is. In this case in gallery.Exec should be giving you back any errors, so instead of doing an if() statement with just yes and no, echo exec(...) instead so you get to see the error.
X-Istence
Do note that on their Wiki they state a different path for ImageMagick: http://wiki.lunarpages.com/Special_Server_Paths
X-Istence
So try /usr/local/bin/convert instead of the above command and see if that works.
X-Istence
I tried to echo exec() and got nothing, just a blank page.I had sent in a ticket asking about ImageMagick, it can be accessed at the following paths:<br>/usr/local/bin/ <br>/usr/lib/ImageMagick <br>/usr/local/lib/ImageMagick <br>/usr/share/ImageMagick <br>If it is working in the current directory will exec('usr/local/bin/convert images/a.pdf images/a.png') try to find ImageMagick in /gallery/usr/local/lib/ImageMagick/ ?
Levi
The path is now correct, I have successfully converted a png to a jpg, I am still having trouble converting a pdf however, so I will post back when I figure it out.
Levi