Let's now resize images by modifying their pixel dimensions and applying various filters for re-sampling.
Download the file
ImageResizeExample.bmp
from the Packt website. We will use this as the reference file to create scaled images. The original dimensions ofImageResizeExample.bmp
are200 x 212
pixels.Write the following code in a file or in Python interpreter. Replace the
inPath
andoutPath
strings with the appropriate image path on your machine.1 import Image 2 inPath = "C:\\images\\ImageResizeExample.jpg" 3 img = Image.open(inPath) 4 width , height = (160, 160) 5 size = (width, height) 6 foo = img.resize(size) 7 foo.show() 8 outPath = "C:\\images\\foo.jpg" 9 foo.save(outPath)
The image specified by the
inPath
will be resized and saved as the image specified by theoutPath
. Line 6 in the code snippet does the resizing job and finally we save the new image on line 9. You can see how the resized image looks by callingfoo.show()
.Let's now specify the
filter
argument...