Commandline Working. PHP Exec not.
Commandline Working. PHP Exec not.
In relation to this users post: http://studio.imagemagick.org/discourse ... f=1&t=8898
I can happily convert a PDF to PNG/JPEG via the commandline but when it comes to doing this via PHP I dont get any success.
I'm lost for what to do now, Google hasnt given me much help apart from unresolved posts to various forums.
Thanks in advance!
I can happily convert a PDF to PNG/JPEG via the commandline but when it comes to doing this via PHP I dont get any success.
I'm lost for what to do now, Google hasnt given me much help apart from unresolved posts to various forums.
Thanks in advance!
Re: Commandline Working. PHP Exec not.
What comand are you using?
You may need to give the full path to Imagemagick - run this and use the output in your code:
You should get something like; convert is /usr/local/bin/convert
You may need to give the full path to Imagemagick - run this and use the output in your code:
Code: Select all
<?php
echo "<pre>";
system("type convert");
echo "</pre>";
?>
Re: Commandline Working. PHP Exec not.
Bonzo wrote:What comand are you using?
You may need to give the full path to Imagemagick - run this and use the output in your code:You should get something like; convert is /usr/local/bin/convertCode: Select all
<?php echo "<pre>"; system("type convert"); echo "</pre>"; ?>
Okay, I ran the code you suggested and I got no response.
This is what im currently running inbid to get the PDF converted:
Code: Select all
exec( "convert -quality 80 \"{$fileName}.pdf\" \"{$fileName}.png\"", $out, $ret );
// or convert -quality 80 "../pdfs/pdf-b9b4a0174c7c01.pdf" "../pdfs/pdf-b9b4a0174c7c01.png"
echo $ret; print_r( $out );
Code: Select all
convert is hashed (/usr/local/bin/convert)
Code: Select all
convert "../pdfs/pdf-b9b4a0174c7c01.pdf" "../pdfs/pdf-b9b4a0174c7c01.png"
Code: Select all
root@atlantic [/home/whosout/public_html]# convert "../pdfs/pdf-b9b4a0174c7c01.pdf" "../pdfs/pdf-b9b4a0174c7c01.png"
Re: Commandline Working. PHP Exec not.
You may have a path problem; try I would try something simple first to prove IM is working
NOTE: rose: is an inbuilt imagemagick image so you do not need to worry about the path etc.
Code: Select all
<?php
exec( "/usr/local/bin/convert rose: -resize 200x200 output.jpg );
?>
<img src="output.jpg"
Re: Commandline Working. PHP Exec not.
http://uploadsafe.com/~whosout/_css/playground.phpBonzo wrote:You may have a path problem; try I would try something simple first to prove IM is workingNOTE: rose: is an inbuilt imagemagick image so you do not need to worry about the path etc.Code: Select all
<?php exec( "/usr/local/bin/convert rose: -resize 200x200 output.jpg ); ?> <img src="output.jpg"
playground.php
Code: Select all
<?php
exec( "/usr/local/bin/convert rose: -resize 200x200 output.jpg" );
?>
<img src="output.jpg">
Re: Commandline Working. PHP Exec not.
I would contact your hosts and get them to check the setup; IM can work from the command line and not from php if the paths are incorrect.
I assume that you have CHMOD the folder you are running the code in to either 755 or 777
I assume that you have CHMOD the folder you are running the code in to either 755 or 777
Re: Commandline Working. PHP Exec not.
To your first question, I installed both ImageMagick and Ghostscript. Its not a managed server, so I would be the guy who is "supposed" to know whats wrong!Bonzo wrote:I would contact your hosts and get them to check the setup; IM can work from the command line and not from php if the paths are incorrect.
I assume that you have CHMOD the folder you are running the code in to either 755 or 777
It was 755, Ive now changed it to 777 and it works.
However its not resizing the image to 200x200
Re: Commandline Working. PHP Exec not.
WoopsTo your first question, I installed both ImageMagick and Ghostscript. Its not a managed server, so I would be the guy who is "supposed" to know whats wrong!
I has resized it but it keeps the aspect ratio so the logest side is 200.
What happens to your original code now ?
Re: Commandline Working. PHP Exec not.
Some coments on your code:
1/ Read the image in first unless yoy want to set the density
2/ Th -quality wants to go just before the save filename
3/ I do not think you need the \" or { in this case.
I would try:
1/ Read the image in first unless yoy want to set the density
2/ Th -quality wants to go just before the save filename
3/ I do not think you need the \" or { in this case.
I would try:
Code: Select all
exec( "convert -density 400 $fileName.pdf -quality 80 $fileName.png", $out, $ret );
Re: Commandline Working. PHP Exec not.
<?phpBonzo wrote:WoopsTo your first question, I installed both ImageMagick and Ghostscript. Its not a managed server, so I would be the guy who is "supposed" to know whats wrong!
I has resized it but it keeps the aspect ratio so the logest side is 200.
What happens to your original code now ?
exec( '/usr/local/bin/convert testpdf.pdf testing.jpg' );
?>
Does not work, nor does it work with quotes around the filenames. Its crazy yet still works in command!
Re: Commandline Working. PHP Exec not.
Bonzo wrote:Some coments on your code:
1/ Read the image in first unless yoy want to set the density
2/ Th -quality wants to go just before the save filename
3/ I do not think you need the \" or { in this case.
I would try:Code: Select all
exec( "convert -density 400 $fileName.pdf -quality 80 $fileName.png", $out, $ret );
Doesnt work
Also:
Code: Select all
<?php
exec( "/usr/local/bin/convert /home/whosout/public_html/_css/testpdf.pdf /home/whosout/public_html/_css/output.png", $output );
print_r( $output );
?>
Array ( [0] => CRIT: rangecheck in .setuserparams [1] => Operand stack: [2] => --nostringval-- --nostringval-- --nostringval-- )
Re: Commandline Working. PHP Exec not.
Try adding this error reporting - IM is not great at error reporting but hopefuly you should get something:
I think you need 777 for a normal php setup but 755 will work for phpsusx or whatever it is.
Code: Select all
<?php
$array=array();
echo "<pre>";
exec("convert -density 400 $fileName.pdf -quality 80 $fileName.png 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
Re: Commandline Working. PHP Exec not.
Code: Select all
Array
(
[0] => CRIT: rangecheck in .setuserparams
[1] => Operand stack:
[2] => --nostringval-- --nostringval-- --nostringval--
[3] => convert: Postscript delegate failed `testpdf.pdf': @ error/pdf.c/ReadPDFImage/645.
[4] => convert: missing an image filename `output.png' @ error/convert.c/ConvertImageCommand/2949.
)
1
Re: Commandline Working. PHP Exec not.
I am afraid we are now at the limit of my knowledge.
IM is working OK and the image can be saved and so it is looking like a ghostscript problem?
Hopefuly somebody else will be online later and can offer some advice.
IM is working OK and the image can be saved and so it is looking like a ghostscript problem?
Hopefuly somebody else will be online later and can offer some advice.
Last edited by Bonzo on 2010-11-15T11:43:16-07:00, edited 1 time in total.
Re: Commandline Working. PHP Exec not.
I think, but my guess is that GhostScript doesn't have the privileges to execute but on SSH as im logged in as root, it does. I do not know how to get around that though
I've reinstalled GhostScript and IM both ways to see if that was the problem. Its currently installed first and IM afterwards.
I've reinstalled GhostScript and IM both ways to see if that was the problem. Its currently installed first and IM afterwards.