Sample python code to resize image

  |   Source

#!/usr/bin/python
import Image

import cStringIO

data=open("test.png","rb").read()

# in real application, I handle the data in memory

img=Image.open(cStringIO.StringIO(data))

img.thumbnail((800,480),Image.ANTIALIAS)

img.save("test-p.jpg","JPEG")

img.thumbnail((128,128),Image.ANTIALIAS)

img.save("test-t.jpg","JPEG")

print "DONE"

Comments powered by Disqus