Re: reducing the wxh of embedded media

Ken Sharp <[email protected]> Fri, 09 Mar 2018 15:02:24 +0000
Newsgroups gmane.comp.printing.ghostscript.devel
Message-ID <[email protected]>
At 08:40 09/03/2018 -0600, Matthew Lenz wrote:


>The embedded images on pages 3-15 are excessive in size for our needs and 
>result in larger than necessary pdf.
>
>I'd like to reduce the height/width of the embedded images as well as 
>convert them to gray.

Height and Width don't have much meaning in PDF, they simply describe the 
number of samples in a bitmap image. The image can be stretched over the 
entirety of a large page, or squeezed up into a tiny thumbnail.

So the 'size' of the bitmap (whether expressed in bytes or the number of 
samples) isn't relevant. A small image scaled over a large page will have a 
low resolution (and therefore poor quality) while a large image squeezed 
into a small thumbnail will have a high resolution, and probably 
excessively high resolution.

Thus the control for the output is the resolution.


>I've got the gray conversion working (-sProcessColorModel=DeviceGray 
>-sColorConversionStrategy=Gray) but I'm not having any luck resizing the 
>embedded images.  All the info I'm finding on reducing image size is with 
>regards to lowering the dpi using the various distiller presets.

That's the way to do it, its the only way to do it. You need to set several 
parameters:

For colour images
=====================
DownsampleColorImages
ColorImageResolution
ColorImageDownsampleThreshold
ColorImageDownsampleType

For gray images
=====================
DownsampleGrayImages
GrayImageResolution
GrayImageDownsampleThreshold
GrayImageDownsampleType

For monochrome images
======================
DownsampleMonoImages
MonoImageResolution
MonoImageDownsampleThreshold
MonoImageDownsampleType

If Downsample.*.Image is true, then the resolution of each image is 
inspected (see my comments above), if it is greater than .*.ImageResolution 
x .*.ImageDownsampleThreshold, then it will be downsampled, using 
.*.ImageDownsampleType to .*.ImageResolution.

Note that certain kinds of downsampling aren't valid for non-integer 
downsampling types and the pdfwrite device may silently substitute a 
different downsampling algorithm in these cases.


>Â  I've been messing with the -g (-dDEVICEWIDTH &Â -dDEVICEHEIGHT) 
>parameter but getting inconsistent (probably not inconsistent just not 
>sure how to interpret the results).

That will have no effect on the image content. Unless you downsample the 
images, they are embedded in the output PDF file unchanged. Actually they 
won't be 'unchanged' because you are changing the colour space, but the 
resolution of the images will be unaffected.

Note that changing DEVICEWIDTHPOINTS and DEVICEHEIGHTPOINTS has no effect 
on most input, and none at all with PDF file, because the input will set 
the media size itself. If you want to fix the media size, you must 
additionally set -dFIXEDMEDIA. This may result in the input being cropped 
to fit. If you want it scaled then you must also set -dFitPage.


>The hope is that ghostscript has some way to do this out of box.

It does, and you've already mentioned it.

This has the feel of commercial usage, so can I please just draw your 
attention to the Ghostscript licence, which is the AGPL version 3, and ask 
you to give it a quick scan to make sure you are compliant with the 
provisions of that licence.


             Ken