Page 1 of 1

Auto-detect optimal image output format, How to

Posted: 2010-02-16T14:49:07-07:00
by rdkill
I am using ImageMagick on a website to process images of scanned books. Text-only pages look the best as GIF/PNG; and mostly-image-filled pages look the best as JPEG. I'd like to find the optimal output format on the fly.

Any recommendations on how to approach this? I would imagine I need to look at the separation of colors to see how badly I need gradients (which JPEG would be ideal for). I'm looking to maximize quality and minimize file size, since they are being served on the web. The easiest solution would be really high quality JPEGs, but I'd really like to optimize the viewing experience.

Possible cases:
1) A full-page color graphic
2) Grayscale text on a FFF background
3) Text on a brown-ish background (likely several shades of brown)
4) Half text, half grayscale graphics
and so on and so on...

Re: Auto-detect optimal image output format, How to

Posted: 2010-02-16T15:14:55-07:00
by snibgo
I suggest that subjective "quality" is hard to determine in software, including ImageMagick.

You might find that creating both PNG and JPG versions, with suitable "-quality" settings, then choosing the smallest of the two, gets you somewhere near.

Re: Auto-detect optimal image output format, How to

Posted: 2010-02-18T13:24:34-07:00
by rdkill
I see. That makes sense. After picking JPEG/PNG, would you recommend sticking to that format for every generated size? The generated images range from a width of ~1100px down to 82px for the smallest zoom.

Re: Auto-detect optimal image output format, How to

Posted: 2010-02-18T15:10:51-07:00
by snibgo
You'll have to do trials, trading off download size, visual appearance and programming complexity.

In my experience, most scanned pages compress best in jpg, even the most graphic kinds. (But your scans may be different.)

Re: Auto-detect optimal image output format, How to

Posted: 2010-02-18T17:14:59-07:00
by rdkill
I have been using JPEG, but I realized that it's less than optimal for some pages such as gray-scale text-only ones. JPEG needs to be pretty high quality to prevent artifacts, but PNG8 would look almost perfect using 8 colors in less than half the size of the JPEG. I wouldn't care if I wasn't serving for the web, but I'm trying to make this thing really quick and responsive.

I'm hoping I can find some PNG and JPEG settings that will consistently produce good quality results, then simply tell the script to keep the one that's smaller.

*begins testing