Posted by & filed under python.

# resize an image using the PIL image library
# free from:
# tested with Python24        vegaseat     11oct2005
import Image
# open an image file (.bmp,.jpg,.png,.gif) you have in the working folder
imageFile = "zFlowers.jpg"
im1 =
# adjust width and height to your needs
width = 500
height = 420
# use one of these filter options to resize the image
im2 = im1.resize((width, height), Image.NEAREST)      # use nearest neighbour
im3 = im1.resize((width, height), Image.BILINEAR)     # linear interpolation in a 2x2 environment
im4 = im1.resize((width, height), Image.BICUBIC)      # cubic spline interpolation in a 4x4 environment
im5 = im1.resize((width, height), Image.ANTIALIAS)    # best down-sizing filter
ext = ".jpg""NEAREST" + ext)"BILINEAR" + ext)"BICUBIC" + ext)"ANTIALIAS" + ext)
# optional image viewer ...
# image viewer  i_view32.exe   free download from:
# avoids the many huge bitmap files generated by PIL's show()
Опубликовать в Facebook
Опубликовать в Google Plus

Leave a Reply

You must be logged in to post a comment.