PDF to JPG not working from php front end

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

PDF to JPG not working from php front end

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PDF to JPG not working from php front end

Post 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.
snibgo's IM pages: im.snibgo.com
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post 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
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post 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");
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG not working from php front end

Post by fmw42 »

Your PHP probably does not find Ghostscript
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post by danfar »

so how can I fix this? any suggestions

thanks
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG not working from php front end

Post 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.
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post by danfar »

if I can see gs under delegates doesnt that mean IM knows about gs?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PDF to JPG not working from php front end

Post by snibgo »

No. It means it wants GS.
snibgo's IM pages: im.snibgo.com
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post by danfar »

ok so how do I add it? should I un install both and reinstall? or do just IM only

thanks
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PDF to JPG not working from php front end

Post by Bonzo »

If you can uninstall and reinstall I would; I believe Ghostscript should be installed first.
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG not working from php front end

Post 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
danfar
Posts: 23
Joined: 2014-12-08T08:22:45-07:00
Authentication code: 6789

Re: PDF to JPG not working from php front end

Post 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?
Post Reply