exec Path

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mssbcons
Posts: 4
Joined: 2012-07-06T06:13:07-07:00
Authentication code: 13

exec Path

Post by mssbcons »

My admin installed Ghostscript and ImageMagik which I am told is at /usr/bin (eg /usr/bin/convert). As I am converting pdf to png, jpegs ect what would my full exec line be?

I found this but surely the path has to be included
<?php
//the path to the PDF file
$strPDF = "my_pdf.pdf";
exec("convert \"{$strPDF}\" -colorspace RGB -geometry 1024 \"output.png\"");
?>

So would it read

exec("/usr/bin/convert \"{$strPDF}\" -colorspace RGB -geometry 1024 \"output.png\"");
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: exec Path

Post by Bonzo »

I did not use the path on my old install and just used convert but since my hosts upgraded I now have to use /usr/local/bin/convert It depends on your setup. Have you tried anything?

This should work as long as you do not have spaces in your filenames - you do not need the { } and extra \"

Code: Select all

exec("convert $strPDF -colorspace RGB -geometry 1024 output.png");
mssbcons
Posts: 4
Joined: 2012-07-06T06:13:07-07:00
Authentication code: 13

Re: exec Path

Post by mssbcons »

Thanks for the path advice I have used both:

But

$strPDF = $_SERVER['DOCUMENT_ROOT']."pdfTest.pdf";
exec("/usr/local/bin/convert $strPDF -colorspace RGB -geometry 1024 output.png");
print "finished";

gives

finished

But output.png is not generated

How know what exec is returning as an error? Thanks again much appreciated
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: exec Path

Post by Bonzo »

If you want confirmation all is OK I would add some code after the exec() to see if the file exists - some times that gives a false result so I tend to try opening the file. This means the file has definatly been creted.

As to error reporting:

Code: Select all

$strPDF = $_SERVER['DOCUMENT_ROOT']."pdfTest.pdf";
$array=array(); 
echo "<pre>";
exec("/usr/local/bin/convert $strPDF -colorspace RGB -geometry 1024 output.png 2>&1", $array);  
echo "<br>".print_r($array)."<br>";  
echo "</pre>";
mssbcons
Posts: 4
Joined: 2012-07-06T06:13:07-07:00
Authentication code: 13

Re: exec Path

Post by mssbcons »

Thanks again for helping

Regardless of path this returns an empty array and a screen output of 1.

$strPDF = $_SERVER['DOCUMENT_ROOT']."/imageTest.php";
$array=array();
echo "<pre>";
exec("/usr/local/bin/convert $strPDF -colorspace RGB -geometry 1024 output.png 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";

i.e.

Array
(
)
1
mssbcons
Posts: 4
Joined: 2012-07-06T06:13:07-07:00
Authentication code: 13

Re: exec Path

Post by mssbcons »

I have discovered 'safe mode' on php needs to be set to off for exec to work. I now get a permissions error which I will follow up on. Thanks again for your help.
Post Reply