Search code examples
pdfjpegghostscript

Ghostscript generate quality thumbnail jpg from pdf


I am generating .jpg thumbnails out of .pdf pages with ghostscript. This is the code I'm using:

gswin64c -dNumRenderingThreads=4 -dNOPAUSE -sDEVICE=jpeg -g125x175 -
dPDFFitPage -sOutputFile=./h%d.jpg -dJPEGQ=100 -r300 -q input.pdf -c quit

Everything is fine except the quality of thumbnails is really bad. I'm hoping for some ghostscript command to increase the quality to imagemagick quality. Btw. Imagemagick generates good quality thumbnails, but it's too slow. Here is an example thumbnail with ghostscript: Example image that get's generated

And here is the image I want. Generated by imagemagick: enter image description here


Solution

  • It would be helpful to supply the original file, without that its speculation as regards better parameters.

    Personally I wouldn't use JPEG, I doubt it offers much compression at such low resolution/media size. It also doesn't perform well on linework and text, which is what your page looks like to me. The combination leads to considerable artefacts in the output.

    The ImageMagick output appears to be heavily anti-aliased, you can get that from Ghostscript by setting -dGraphicsAlphaBits, -dTextAlphaBits OR by oversampling the resolution and then downsampling, using -dDownScaleFactor.

    Of course, the performance of Ghostscript when producing anti-aliased output will be reduced compared to the normal output. You can't get something for nothing 'better quality' is going to cost you somewhere along the line.

    Note that at the page size you are using -dNumRenderingThreads will have no effect whatsoever. You have to be running a display list for that to have any effect, and such a tiny page will be rendered as a bitmap in memory.