ghostscript not working in php

帅比萌擦擦* 提交于 2019-12-10 22:38:38

问题


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


回答1:


in my case i've tryed using imagmagick to extract the first image from PDF using convert but it didn't work so i used Ghostscript with the below script and it works perfectly in the webserver :

gs -sDEVICE=jpeg -o d:/output.jpg -dFirstPage=1 -dLastPage=1 -dNOPAUSE -dJPEGQ=100 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -r150 -dUseCropBox -dUseTrimBox d:/input.pdf

However after testing many ghostscript ver, even the latest ones, i found out the 9.06 is the most stable ghostscript ver




回答2:


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, like -r$resolution.



来源:https://stackoverflow.com/questions/19080032/ghostscript-not-working-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!