A
Almad
Hello,
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=',
str(id)])
uf = urlopen(uri).read()
f = tmpfile()
f.write(uf)
f.seek(0)
logging.debug('Resizing image %s' % id)
img = Image.open(f)
prev = img.copy()
img.thumbnail((180,180))
if prev.size[0] > 640 or prev.size[1] > 640:
prev.thumbnail((640,640))
# save resized to temporary files
f.seek(0)
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,
Almad
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=',
str(id)])
uf = urlopen(uri).read()
f = tmpfile()
f.write(uf)
f.seek(0)
logging.debug('Resizing image %s' % id)
img = Image.open(f)
prev = img.copy()
img.thumbnail((180,180))
if prev.size[0] > 640 or prev.size[1] > 640:
prev.thumbnail((640,640))
# save resized to temporary files
f.seek(0)
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,
Almad