[Image-SIG] Problem when resizing large JPEG to thumbnail

Etienne Desautels tiit at sympatico.ca
Tue Sep 1 04:44:01 CEST 2009


Hi,

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:
http://www.teknozen.net/resize_pil.html

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 ?

Etienne


More information about the Image-SIG mailing list