phMagick :: Thumbnail from Pdf or Video file
Please note that for videos you must have the correct codecs installed in your server and for pdf you need ghostscript
It's quite simple to use
$p = new phmagick('','destination.png'); $p->acquireFrame('filename.pdf');
parameters:
file: the path to the file
I have noticed that PDF 2 PNG is possible but only the first page; Is it possible to get either the full pages or we can specify what page to convert from PDF 2 PNG, or maybe both?
TQ
Hi Khairil
try using frames= 99999 or something like that and you will end up with a series of files numbered sequentially each one representing a page from the PDF
Thank-you sir, I will try it immediately. Another question sir, other than PDF or Video file, is it possible to get an image from a full html page, with a given URL?
Sorry sir, the ‘ function acquireFrame($file, $frames=0){‘ i’ve changed to 99999 doesn’t work. It only list the page number starting from 0, any more ideas?
Hi Khairil,
I’ve never tested it, but imagemagick supports converting html to an image so it should work.
It’s my bad, I’ve explained you the wrong way.
If you want all the pdf pages saved as an image do like this :
you will end up with pdf-save-0.png, pdf-save-1.png, and so on
you you just want a specific page then you use the acquireFrame() with $frames equal to the page number (pages start at 0)
Thanks a lot, i’ll buy you a beer one day if my current project sells, and thats a promise
Hi,
I am getting following error message, when i am converting from PDF file to image file using phmagick class.
Imagemagick version : ImageMagick-6.5.7-6-Q16
Error :
Array
(
[0] => convert: `%s’: %s “gswin32c.exe” -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 “-sDEVICE=pnmraw” -dTextAlphaBits=4 -dGraphicsAlphaBits=4 “-r72x72″ -dFirstPage=1 -dLastPage=1 “-sOutputFile=C:/WINDOWS/TEMP/magick-WoV5rojT” “-fC:/WINDOWS/TEMP/magick-WTLcMqP_” “-fC:/WINDOWS/TEMP/magick-aE6VvNda”.
[1] => convert: Postscript delegate failed `1.pdf’: No such file or directory.
[2] => convert: missing an image filename `imgpreview.png’.
)
Please share your thoughts. Thank you!
Hello,
You need to have GhostScript installed on your server
I have used Phmagick class. Its converting correctly from PDF file to image, but i am getting below warning message.
“**** Warning: Fonts with Subtype = /TrueType should be embedded. [1] => But Verdana is not embedded. [2] => **** Warning: Fonts with Subtype = /TrueType should be embedded. [3] => But Verdana,Bold is not embedded. [4] => **** Warning: Fonts with Subtype = /TrueType should be embedded. [5] => But Arial is not embedded. [6] => **** Warning: Fonts with Subtype = /TrueType should be embedded. [7] => But TimesNewRoman is not embedded. [8] => **** Warning: Fonts with Subtype = /TrueType should be embedded. [9] => But Arial,Bold is not embedded. [10] => [11] => **** This file had errors that were repaired or ignored. [12] => **** The file was produced by: [13] => **** >>>> Acrobat
PDFWriter 5.0 for Windows NT <<< **** Please notify the author of the software that produced this [15] => **** file that it does not conform to Adobe’s published PDF [16] => **** specification. [17] => )”
Please share your thoughts. Thank you!
I believe it has something to do with your ghostscript installation or missing fonts
Hi,
This is great. It seems to work on short pdfs but on pdfs with more pages my thumb comes out as a skewed black and white image, any ideas on what I might be doing wrong here?
I want to obtain the number of pages in the pdf to see how many images were generated…
Hi Rafael,
I don’t think you can do that with imagemagick
Hi Roland
If you can email me the problematic pdf I can have a look, have you tried to update your ghostscript install ?
(imagemagick uses ghostscript to convert pdf so the problem might be there )
Hi,
I am getting following error message, when i am converting from PDF file to image file using phmagick class.My server os is linux,and I know the gs command is at ‘opt/bin/’ ,what should I do .
Thank you.
phMagick: Error executing “/opt/bin/convert -scale “200x>” -quality 80 -strip “ttt.pdf” “/opt/bin/”"
return code: 1
command output :”sh: gs: command not found
convert: Postscript delegate failed `ttt.pdf’: @ error/pdf.c/ReadPDFImage/663.
convert: missing an image filename `/opt/bin/’ @ error/convert.c/ConvertImageCommand/3011.”
Notice: exception ‘phMagickException’ in /share/MD0_DATA/Web/edit/phmagick/phmagick.php:189 Stack trace: #0 /share/MD0_DATA/Web/edit/phmagick/plugins/resize.php(46): phmagick->execute(‘/opt/bin/conver…’) #1 [internal function]: phMagick_resize->resize(Object(phmagick), 200, 0) #2 /share/MD0_DATA/Web/edit/phmagick/phmagick.php(205): call_user_func_array(Array, Array) #3 [internal function]: phmagick->__call(‘resize’, Array) #4 /share/MD0_DATA/Web/try.php(8): phmagick->resize(200, 0) #5 {main} in /share/MD0_DATA/Web/edit/phmagick/phmagick.php on line 189
Array
(
[0] => Array
(
[cmd] => /opt/bin/convert -scale “200x>” -quality 80 -strip “ttt.pdf” “/opt/bin/”
[return] => 1
[output] => Array
(
[0] => sh: gs: command not found
[1] => convert: Postscript delegate failed `ttt.pdf’: @ error/pdf.c/ReadPDFImage/663.
[2] => convert: missing an image filename `/opt/bin/’ @ error/convert.c/ConvertImageCommand/3011.
)
)
)
1
Hi,
I can’t seem to convert PDFs to JPGs at all. I managed to convert a JPG to PDF, but not the other way round.
I installed Ghostscript. Is there something I should do so Imgmagick and ghostscript are working together properly?
I don’t get any error from phMagick.
Hi there!
One quick question, please. General speaking, would it be safe for my server if I enable the exec() command in order to make the aforementioned script run? If not, how could I skip this command?
EuaLin
You need the exec command
as long as you sanitize the user input and make good use of open_basedir() you should be safe
please check imagemagick.org website
please install ghostscript