简体   繁体   中英

imagemagick convert does not work through php

imagemagick convert does not work through php shell_exec but does through a shell.

In a shell convert file.pdf file.png works fine. But when I have this within a php file as shell_exec('convert file.pdf file.png'); Then I get no output! I have the permissions to do this, so I think it isn't that that's the problem; I have checked the directory I am in by way of getcwd() and this is also ok.

I know shell_exec works because I have used it earlier in the code and that works fine.

Any ideas?

I got the solution thanks to Crontab from another thread. I quote from there:

[I]f you're trying to convert a PDF to a PNG using ImageMagick ... even using the full path to ImageMagick's convert won't work if the script's PATH doesn't contain the path location to Ghostscript also. Without messing with any user paths, you could add:

 putenv("PATH=/usr/local/bin:/usr/bin:/bin"); 

Or something similar depending on your setup. The gs executable has to be in your script user's path somewhere or ImageMagick will fail to convert PDF or EPS files.

Try the full path to convert , ie shell_exec('/usr/bin/convert file.pdf file.png); . You can use which convert to find the location on your system.

There are several reason why this could happen, but I suggest reading this page and the user comments:

http://php.net/manual/en/function.shell-exec.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM