Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #688 > unrolled thread

Making thumbnails efficiently with ghostscript

Started bybugbear <bugbear@trim_papermule.co.uk_trim>
First post2012-05-22 14:05 +0100
Last post2012-05-22 14:11 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.postscript


Contents

  Making thumbnails efficiently with ghostscript bugbear <bugbear@trim_papermule.co.uk_trim> - 2012-05-22 14:05 +0100
    Re: Making thumbnails efficiently with ghostscript Thomas Kaiser <Thomas.Kaiser@phg-online.de> - 2012-05-22 14:11 +0000

#688 — Making thumbnails efficiently with ghostscript

Frombugbear <bugbear@trim_papermule.co.uk_trim>
Date2012-05-22 14:05 +0100
SubjectMaking thumbnails efficiently with ghostscript
Message-ID<PKKdnck_eruzEibSnZ2dnUVZ8lSdnZ2d@brightview.co.uk>
(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

[toc] | [next] | [standalone]


#689

FromThomas Kaiser <Thomas.Kaiser@phg-online.de>
Date2012-05-22 14:11 +0000
Message-ID<slrnjrn7kd.26fn.Thomas.Kaiser@phg-online.de>
In reply to#688
["Followup-To:" comp.text.pdf]
bugbear wrote in <news:PKKdnck_eruzEibSnZ2dnUVZ8lSdnZ2d@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web