Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ghostscript not working in php

I want to create php page which convert first page of pdf file to jpg image. I have these code.

exec('convert -density 300 "24.pdf"[0] "24-1.jpg"', $output); print_r(array_values($output));

It not work. I have tested following code(with command prompt and php) and it works well. Exec('DIR', $output); print_r(array_values($output)); //to check command

Exec('convert', $output); print_r(array_values($output)); //to check imageMagick

Exec('convert -transverse 22.jpg 22-1.jpg', $output); print_r(array_values($output)); //to check imageMagick function

But when I tried this command

Exec('convert -transverse 22.pdf[0] 22-1.jpg',$output); print_r(array_values($output)); //to check imageMagick function with pdf

It not work but all above command is working with command prompt. It seems that imageMagik working well but ghostscript have problem with php. Please can you tell me why ghostscript is not working with php.

I'm using Window 7 Ultimate, IIS7.5 and PHP 5.3. ImageMagick-6.8.7-Q16 ghostscript 9.10

Thanks and regards Mohammed Shaikh

like image 745
Mohammed Umar Shaikh Avatar asked Feb 16 '26 21:02

Mohammed Umar Shaikh


1 Answers

Try using this

exec("<full path to binary> '-dNOPAUSE' '-sDEVICE=jpeg' '-r<resolution>'
     '-g<dimensions>' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4'
     '-o<where you want the image stored>' '-dJPEGQ=<quality - I used 90>'
     '<pdf file to resize>'", $outputArray);

If the placeholders are filled in using variables, the variables - like $resolution - just go straight in to the command, e.g. -r$resolution.

like image 59
craned Avatar answered Feb 18 '26 13:02

craned



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!