Add option to set DownsampleThreshold #21
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added the ability to set the DownsampleThreshold using the
-t
flag. This is desirable because the default threshold is 1.5, which results in a high variance of image quality within a document and larger than necessary file sizes.When ghostscript considers an image for downsampling, it checks the desired dpi against the actual dpi for an image. If the actual dpi is "bigger enough" than the desired dpi, the image is downsampled. What does "bigger enough" mean? That's configurable with an option called the DownsampleThreshold.
By default, ghostscript uses 1.5 as the downsample threshold. This means that if you desire the images to have a dpi of 300 and set that resolution (in this script using
-r
), images above 300*1.5 = 450 dpi will be downsampled down to 300. Images with 440 dpi will remain 440 dpi.The result is a document which may have images of vastly differing appearance quality, and at some resolutions that can be a bit visually jarring. Moreover, without this setting if a user is targeting a specific file size they will continually reduce the resolution setting until that filesize is met, and the file that results would have perhaps the same average image quality (that is, the same average image quality as a file of equivalent size made using a lower threshold but higher dpi), but a much worse minimum image quality than a file made with a low DownsampleThreshold (but higher dpi) since the variance is going to be much higher.
Now, it wouldn't be worthwhile to convert an image with 310 dpi to 300 dpi because the size savings would be negligible and the image would be more than 10 dpi worse (any conversion naturally incurs a quality loss irrespective of dpi), which is why this feature exists to begin with. I simply make the case that this script would benefit from exposing that threshold so that users can easily modify it. A more reasonable threshold than the default of 1.5 is probably closer to 1.1 or so in my testing, but I've left my opinion out of this commit.
The default value for
-t
is set to 1.5 as specified by the documentation, so by default no behavior is changed. Read more about this feature on this page (search DownsampleThreshold).In the end I'm not sure I've explained myself well so please ask questions if I wasn't clear.