Page 1 of 4

PDF to JPG not working from php front end

Posted: 2014-12-08T08:34:39-07:00
by danfar
PDF to JPG not working from php front end
It works fine on command line using
convert test.pdf test123.jpg

the path for both are /usr/bin/convert and /usr/bin/gs
versions are
imagemagick 6.5.4-7
ghostscript 8.70

I have tried this code and a couple of others from the web
<?php
Replace input.jpg with the name of a jpg image in the same folder as this code and run it.
exec("/usr/bin/convert test.pdf jastest123.jpg");
?>

it convert from jpg to pdf but not pdf to jpg

any help would be appreciated

thanks

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T09:03:28-07:00
by snibgo
Converting from pdf to jpg needs ghostscript. This will be a configuration problem with php. I don't know the answer, but it will be on these forums somewhere.

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T09:36:48-07:00
by danfar
Yes i have ghostscript installed and it works on command line

all i have read is they need the same path e.g. /usr/bin/

/usr/bin/convert
/usr/bin/gs

but how to I make it work on php

I even tried this from http://www.veryinteractivepeople.com/?p=521
but nothing happens

<?php
ini_set('display_errors', 1);
$pdf='test.pdf';
$quality=90;
$res='300x300';
$exportName="pdf_export_" . time();
$exportPath=realpath(dirname(__FILE__))."/$exportName/fullres/%03d.jpg";

mkdir(realpath(dirname(__FILE__))."/$exportName");
mkdir(realpath(dirname(__FILE__))."/$exportName/fullres");

set_time_limit(900);
exec("'gs' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4' '-o$exportPath' '-r$res' '-dJPEGQ=$quality' '$pdf'",$output);

for($i=0;$i<count($output);$i++)
echo($output[$i] .'<br/>');
?>


but what else?

thanks

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T10:23:10-07:00
by danfar
how can I call ghostscript directly

exec("/usr/bin/convert test.pdf jastest123.jpg");

for e.g for gs
exec("/usr/bin/gs test.pdf jastest123.jpg");

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T10:45:15-07:00
by fmw42
Your PHP probably does not find Ghostscript

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T12:22:11-07:00
by danfar
so how can I fix this? any suggestions

thanks

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T12:53:02-07:00
by danfar
if i run
convert -list configure

I can see gs under delegates along with freetype fontconfig etc

so that means imagemagick see's gs?

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T13:20:57-07:00
by fmw42
I think your PHP configuration needs to point to GS or at least a version of IM that knows about GS. Search the forum. There may have been topics about this before.

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T13:38:40-07:00
by danfar
if I can see gs under delegates doesnt that mean IM knows about gs?

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T13:58:51-07:00
by snibgo
No. It means it wants GS.

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T14:21:03-07:00
by danfar
ok so how do I add it? should I un install both and reinstall? or do just IM only

thanks

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T14:37:58-07:00
by Bonzo
If you can uninstall and reinstall I would; I believe Ghostscript should be installed first.

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T14:41:41-07:00
by danfar
it was a pain to even get this far - is it possible i can add the path to the delegates.xml? where would it be? if I can get the ssh command that would be kool


thanks for you help

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T15:09:00-07:00
by fmw42
danfar wrote:if I can see gs under delegates doesnt that mean IM knows about gs?
If you see gs under delegates from convert -version or convert -list configure, then Imagemagick should be seeing it. That is why it works under the terminal. The problem, I think, is that PHP is not finding it for use with Imagick

Re: PDF to JPG not working from php front end

Posted: 2014-12-08T15:44:49-07:00
by danfar
so this guy is wrong
Postby snibgo ยป 2014-12-08T15:58:51-05:00

No. It means it wants GS ??

how do I fix it??
can i pay someone to fix this?