graphicsmagick outputs PDF instead of JPG?

40 Views Asked by At

Create thumbnail (JPG) of PDF file

gm convert -density 50 input.pdf[0] -background white -resize 140x140 -strip -quality 40 thumb.jpg

Can someone tell my why this command output a PDF as thumb.jpg? The contents of thumb.jpg is a PDF but should be JPG

gm -version
GraphicsMagick 1.3.42 2023-09-23 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2023 GraphicsMagick Group.

I use the exact same command on another computer with same version of graphicsmagick and the output is JPG in the thumb.jpg file ?!

update

gm convert -verbose -density 50 input.pdf[0] -background white -resize 140x140 -strip -quality 40 thumb.jpg
gm convert: "/usr/local/bin/gs" "-q" "-dBATCH" "-dSAFER" "-dMaxBitmap=50000000" "-dNOPAUSE" "-sDEVICE=pnmraw" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4" "-r50x50" "-dFirstPage=1" "-dLastPage=1" "-sOutputFile=/tmp/gmBCanus" "--" "/tmp/gmsygPXL" "-c" "quit".
input.pdf PDF 413x585+0+0 DirectClass 8-bit 707.9Ki 0.000u 0m:0.000776s (296.8Mi pixels/s)
input.pdf PDF 413x585=>99x140+0+0 DirectClass 8-bit 0.010u 0m:0.002107s (109.3Mi pixels/s)
input.pdf=>thumb.jpg JPG 413x585=>99x140+0+0 DirectClass 8-bit 0.000u 0m:0.000652s (353.5Mi pixels/s)

The output of thumb.jpg

%PDF-1.2 
1 0 obj
<<
/Title (thumb)
/CreationDate (D:20240116190220)
/ModDate (D:20240116190220)
/Producer (GraphicsMagick 1.3.42 2023-09-23 Q8 http://www.GraphicsMagick.org/)
>>
endobj
2 0 obj
<<
...
1

There are 1 best solutions below

0
K J On

There is only one difference in your 1.3.42 Unix command and my 1.3.42 Windows one, and that is:-
I declare the files at the end infile.pdf then out.jpg .

gm convert -verbose -density 50 -background white -resize 140x140 -strip -quality 40 "..\..\Sample (1).pdf" out.jpg

enter image description here

JPEG, quality: 40, subsampling ON (2x2) image 108 x 140 Pixels (0.77)

You can bypass GraphicsMagick and faster simply use GS direct, either,

>%gs% "-q" "-sDEVICE=jpeg" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r50 -dDownScaleFactor=3"-oout2.jpg" -dJPEGQ=40  "..\..\Sample (1).pdf"

OR currently replace -dJPEGQ=40 with -dQFactor=1.25 both have the same effect.

>%gs% "-q" "-sDEVICE=jpeg" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r50 -dDownScaleFactor=3"-oout2.jpg" -dQFactor=1.25  "..\..\Sample (1).pdf

JPEG, quality: 40, subsampling ON (2x2), but file size was bigger as 141 x 183 Pixels (0.77) because I only downscaled by 3, If I downscale by 4 it is closer as 106 x 137 Pixels (0.77)

enter image description here