Python provides a lot of useful tools and libraries to handle images.
If you want to resize an image, for example if you want to create a thumbnail, you can use the following few lines of python code:
# Importing the needed library import Image # Opening the file gg.png imageFile = "gg.png" im1=Image.open(imageFile) # Set the new size width = 100 height = 100 # Set the filter to apply when resizing im2 = im1.resize((width, height), Image.NEAREST) # Save the image with a new name im2.save("resized" + ".png")
The program is really simple and self explanatory, I want to add that you can use a different filter to apply when resizing. You can choose a filter in the following set:
NEAREST
BILINEAR
BICUBIC
ANTIALIAS
If you want you can change this program to handle the command line arguments, in this way you can pass, to the program, a variable number of input files and then it will apply the resize to all the files.
Next week I’ll show you how to implement this feature.
Gg1