PIL thumbnails unreasonably large
larry.bates at websafe.com
Wed May 10 17:22:55 CEST 2006
> I wonder how do I create reasonable thumbnails from JPEG with PIL.
> My code:
> logging.debug('Downloading image %s' % id)
> uri = ''.join([config['photo']['masterpath'], '?p=',
> uf = urlopen(uri).read()
> f = tmpfile()
> logging.debug('Resizing image %s' % id)
> img = Image.open(f)
> prev = img.copy()
> if prev.size > 640 or prev.size > 640:
> # save resized to temporary files
> img.save(f, "JPEG", quality=50)
> fp = tmpfile()
> prev.save(fp, "JPEG", quality=200)
> Well, works fine, but img size is about 0,5 MB (!), but strangely, prev
> one is around 200 kb.
> How do I change this? I tried to play with various quality settings,
> but with no effect. img thumbnail is supposed to be < 10 kb...
> Thank You,
JPEG quality 200 is overkill, btw -- it completely disables JPEG's
quantization stage, and "mainly of interest for experimental pur-
poses", according to the JPEG library documentation, which
"Quality values above about 95 are NOT recommended for
normal use; the compressed file size goes up dramatically
for hardly any gain in output image quality."
More information about the Python-list