-
Book Overview & Buying
-
Table Of Contents
Python Multimedia
By :
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 of ImageResizeExample.bmp are 200 x 212 pixels.
Write the following code in a file or in Python interpreter. Replace the inPath and outPath 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 the outPath. 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 calling foo.show().
Let's now specify the filter argument...
Change the font size
Change margin width
Change background colour