

The Image.resize() method returns a resized copy of the source image. Instead, it returns another Image with the new dimensions. The resize() function doesn’t modify the used image. To resize an image, you have to call the resize() method on the image object and passing in the two-integer tuple argument representing the width and height of the resized image. You can see in the output that right now, the size of the source image is: (4000, 6000).Īfter resizing the image, it will be different.

Print('The palette of img is: ', img.palette) Print('The format of img is: ', img.format) If you want to get the palette of the source image, then you can use the image.palette() function. If you want to get the size of the source image, then you can use the image.size() function. If you want to get the mode of the source image, then you can use the image.mode() function. If you want to get the format of the source image, then you can use the image.format() function.

You can get some information about the image using the image object’s attributes.
#Pillow resize image code
We have handled that exception in our code by printing the message in the console. If the path we have provided is not correct, then it will throw FileNotFoundError exception. For example, on the macOS, it is opening on preview software. The show() method displays the image on the external viewer. You can show the image by calling the show() method on the obtained object. Print('Provided image path is not found')Īfter obtaining the Image object, you can now use the methods and attributes defined by the class to process and manipulate it. To load the image from a file system, we use the open() method from the Image module and passing the path to the image.
#Pillow resize image install
We won’t list the different options here, and you can find the postulate for your specific OS in this installation guide.Īfter installing the required libraries, you can install Pillow with `pip.
