A common target is something like a thumbnail
that will fill 128x128 in x, y, or both.
But if the input is small (like a postage stamp)
the rendering resolution may not be high to
make enough pixels.
Conversely, if the input is large
(like a poster) the rendering may make
far too many pixels, wasting CPU.
The new (to me, at least) options:
-dPDFFitPage and -dEPSFitPage claim to be designed
for thumbnail creation, and do indeed
solve the "wrong number of pixels" issue.
But unless the aspect ratio of the page
is the same as that of the src, I get whitespace
in the thumbnail.
Does anyone have a (simple...) path through this thicket?
BugBear
> The new (to me, at least) options:
> -dPDFFitPage and -dEPSFitPage claim to be designed
> for thumbnail creation, and do indeed
> solve the "wrong number of pixels" issue.
>
> But unless the aspect ratio of the page
> is the same as that of the src, I get whitespace
> in the thumbnail.
>
> Does anyone have a (simple...) path through this thicket?
If the aspect ratio is wrong then you have a choice of:
1) Scaling the largest side, and accepting that there will be white
space along the shorter sidde.
2) Scaling the x and y independently. The bitmap will be distorted which
is regarded as unacceptable for most purposes but might be OK for
thumbnails I suppose.
If you want '1' then the various 'fit' parameters will do it for you (or
you can set a fixed media size and set the PageSize Policy to scale to
fit).
If you want to scale the axes independently then you need to install a
custom setpagedevice which inspects any PageSize requests, discards
them, but uses the information to set the CTM so that the x and y axes
are scaled separately.
Something like:
/oldsetpagedevice /setpagedevice load bind def
/setpagedevice {
dup /PageSize known { %% Does dict contain PageSize
dup /PageSize get %% get the requested media size
%%
%% scale the page here
%%
dup /PageSize undef %% Remove the media size request from the dict
} if
dup length 0 gt { %% dict may have been modified and may be empty
oldsetpagedevice %% process any remaining requests
}{
pop %% Throw dict away if empty
} ifelse
} bind def
Caveat: I haven't actually tried this code. It may be required to store
the original CTM so that multiple setpagedevice requests don't end up
continuously scaling the output.
Ken
Thanks for that - I was considering (also) altering the gs_epsf.ps
and pdf_main.ps (where PDFFitPage and EPSFitPage are implemented)
and adding a new variation.
Cowardice may prevent me... ;-)
The behaviour I want can be nicely specified as
widthxheight
per this language:
http://www.imagemagick.org/script/command-line-processing.php#geometry
With a vector source (eps/pdf) there no deterrent to scaling up,
whereas in Imagemagick (normally) scaling up a small number
of pixels to get "more data" doesn't work well.
BugBear
> The behaviour I want can be nicely specified as
>
> widthxheight
> per this language:
> http://www.imagemagick.org/script/command-line-processing.php#geometry
The seems (to me, maybe I'm mis-understanding) to do what the fit stuff
is supposed to do. It compares the width and height requested against
the width and height of the media, and selects the smallest scale factor
which will fit both of the dimensions onto the media.
Applying this scale to both dimensions preserves the aspect ratio, but
will leave white space if the aspect ratio of the requested input and
media differ.
So if I try to fit a A4 page into a square thumbnail, the page will be
scaled until the vertical fits, and so there will be white space at the
right edge.
You should be able to achieve this by selecting the required media,
setting -dFIXEDMEDIA (in GS) and then picking one of the Fit switches.
I thought you wanted to fill the thumbnail and didn't care about the
aspect ratio.....
Ken
I'm actually trying to make "good" thumbnails for inputs
of widely varying size and aspect ratio.
In terms of quality of output, this could be achived by simply using
an arbitrarily high rendering resolution, -dEPSFCrop (in the cas of EPS)
and then using ImageMagick to subsample.
But for large inputs (e.g. posters, broadsheet newspaper cente spreads)
the rendering step would be expensive.
BugBear
> I'm actually trying to make "good" thumbnails for inputs
> of widely varying size and aspect ratio.
>
> In terms of quality of output, this could be achived by simply using
> an arbitrarily high rendering resolution, -dEPSFCrop (in the cas of EPS)
> and then using ImageMagick to subsample.
Hmmm. The crop function shouldn't affect the resolution, just the
PageSize. If you select fixed media and set the resolution then using
any of the 'fit' opetions should cause the file to be scaled as erquired
to fit the media.
Maybe you could post an example or two of the PostScript/PDF files, and
the kind of output you're looking for ?
The kind of subsampling that image applications use is much more likely
to give 'nice' results than rendering at a lower reoslution with GS,
including scaling image content down which is done as cheaply as
possible.
Ken
I think you meant "downscaling", not "subsampling". The way good
applications do downscaling is more like "supersampling" than
"subsampling".
=======================================================
Anyway, one should be aware even with that. E.g., doing Fourier
analysis, imagemagicks default downscaling (sinc, IIRC) gives almost
ideal (MTF) reproduction up to 70% of Nyquist; however, the result
STILL looks blurry.
Doing some experiments (with radius=1 Gauss), I found that a
post-rescaling step
-unsharp 0x1+0.66+0
more or less restores the visual sharpness of text and line graphic.
(Of course, it messes up with linearity of MTF...)
=======================================================
So for good thumbnails, I would render PS at 3x image size, then would do
-resize 33.3333333333% -unsharp 0x1+0.66+0
in ImageMagick.
Hope this helps,
Ilya