[Image-SIG] Problem when resizing large JPEG to thumbnail
Laura & Edward Cannon
cannon.el at gmail.com
Tue Sep 15 17:59:21 CEST 2009
On Mon, Aug 31, 2009 at 7:44 PM, Etienne Desautels <tiit at sympatico.ca> wrote:
> I'm using sorl-thumbnail in Django to automatically resize my images.
> sorl-thumbnail use PIL to do is image manipulations.
> Unfortunately the result thumbnails are far from pretty. You can see some
> tests here:
> Here's the code I (and sorl) use to create the thumbnails:
> im = Image.open('source.jpg')
> if im.mode not in ("L", "RGB", "RGBA"):
> __im = im.convert("RGB")
> im = im.crop((568, 783, 3164, 3379))
> im = im.resize((70, 70), resample=Image.ANTIALIAS)
> im.save('pil.jpg', "JPEG", quality=95)
> Pretty straightforward. I did some tests with ImageMagick to compare the
> result. The difference is huge. The ImageMagick thumbnail looks great. In
> contrast he PIL thumbnail look blocky and blurry at the same time and the
> colors are all fade out. I don't think the jpeg compression is the problem,
> I set it to 95.
> I did a test with resample=Image.BICUBIC and the result is really bad. But I
> don't think that BICUBIC was really applied because I got the exactly same
> result when I use resample=Image.NEAREST.
> Also, at the beginning, my source file was a TIFF in CMYK. The color of the
> generated thumbnail was completely off. That's why I convert it to RGB JPEG
> in Photoshop.
> So after experimenting, I see 3 problems:
> 1. Resize with ANTIALIAS from a large JPEG to a small thumbnail give poor
> image quality.
> 2. BICUBIC, when set, is not applied. Instead NEAREST is use.
> 3. Converting from TIFF CMYK to RGB shift the colors dramatically.
> Is all theses points are normal behavior ?
> Image-SIG maillist - Image-SIG at python.org
I am not familiar with sorl-thumbnail, so I can't say as to the exact
workings, but from your example it looks like you are just using PIL.
The thumbnail looks ok to me, the only thing that perhaps might be
different between the ImageMagic and the PIL is a color profile. PIL
does not automatically retain extra information attached with an image
(too hard to tell if it is still valid in the general case) so perhaps
if your monitor is calibrated nicely you would notice a difference.
As to the CMYK issue, this has been discussed before, and is still and
open issue, I believe, although there might be a workaround--search
the mailing lists.
More information about the Image-SIG