Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making thumbnails efficiently with ghostscript

8 views
Skip to first unread message

bugbear

unread,
May 22, 2012, 9:05:50 AM5/22/12
to
(I've asked this before, but the thread fizzled)

http://groups.google.com/group/comp.lang.postscript/browse_thread/thread/ca973ffaf885834c/56f107d7b68ee435?hl=en#56f107d7b68ee435

I would like to use ghostscript to make a thumbnail of the first page of a PDF file,
or an EPSF file, to the following spec.

* The thumbnail must have the SAME aspect ratio as the original
* the size of the longest side of the thumbnail must be 128 pixels

The correct pixels can be easily made, by simply rendering at a "too-high"
resolution, and then using ImageMagick:

convert <raster> -resize 128x128 <thuumbnail>

But this can be resource hungry for large media sources. Setting the
resolution high enough to get good thumbs for tiny images
(e.g. a business card image) leaves the resolution FAR
too high for large images (like a newspaper page).

Using info from the previous thread the closest approach is to use these flags:

-r72 -dDEVICEWIDTHPOINTS=128 -dDEVICEHEIGHTPOINTS=128 -dPDFFitPage -dEPSFitPage

Which gives me a 128x128 raster every time. But if the aspect ratio
of the original is NOT 1:1, I either get white padding
on the right, or white padding on the top.

Can anyone suggest a way to get my "dream" thumbnail,
i.e. the same pixels as I'm currently getting, but with
no padding?

The closest I can get at the moment is a second pass with ImageMagick using
options to trim any exterior whitespace

-bordercolor white -border 1x1 -trim +repage

But this will remove any peripheral white
*content* as well as the white padding from the rendering.

All help welcomed (and I bet I'm not the only one wanting this)

BugBear

Thomas Kaiser

unread,
May 22, 2012, 10:11:25 AM5/22/12
to
["Followup-To:" comp.text.pdf]
bugbear wrote in <news:PKKdnck_eruzEibS...@brightview.co.uk>
> I would like to use ghostscript to make a thumbnail of the first page of a PDF file,
> or an EPSF file, to the following spec.
>
> * The thumbnail must have the SAME aspect ratio as the original
> * the size of the longest side of the thumbnail must be 128 pixels
>
> The correct pixels can be easily made, by simply rendering at a
> "too-high" resolution, and then using ImageMagick:

Use the dimensions of the trimbox (or mediabox if missing), do some math
to get the approriate resolution for an image with at least 256x256
pixels and then use this as $MyRenderResolution. This

gs -dUseTrimBox -q -dBATCH -dNOPAUSE -r${MyRenderResolution} \
-sDEVICE=... -dDOINTERPOLATE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
-dMaxBitmap=100000000 -dMaxPatternBitmap=2000000 -sOutputFile=... \
-c 100000000 setvmthreshold -f /path/to/pdf

will produce an image with correct aspect ratio (-dTextAlphaBits=2 and
-dGraphicsAlphaBits=2 should work a bit faster without decreasing
rendering quality since you get an image with twice the pixel dimensions
as necessary).

When you scale down using ImageMagic in a second step you can then apply
some slight sharping or unsharp masking which will produce superiour
results.

Regards,

Thomas
0 new messages