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\"");
exec Path
Re: exec Path
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 \"
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");
Re: exec Path
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
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
Re: exec Path
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:
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>";
Re: exec Path
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
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
Re: exec Path
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.