4/11/2023 0 Comments Python simpleimageIncase we want to resize it, and make it of size 440 * 600px, can be done by: from PIL import Image The size(dimensions) of our current image file is 400 * 260px. Image = Image.open('statue_of_unity.jpg')Ī new image file is created and save in our default directory. Convert to another image typeĬonverting an image of one type (jpeg) to another(say, png) is also very easy. Image.save('statue_of_unity_gs.jpg') ResultĪfter running above program, a file “statue_of_unity_gs.jpg” is created in your current working directory. Image = Image.open('statue_of_unity.jpg').convert('L') ![]() #Read an image & convert it to gray-scale To convert an image to grayscale, display it and then save it is very easy, just do the following: #Import required library The show() function will display the image using operating systems default application. CMYK or RGB) and the size will report the dimensions of the image in pixels (e.g. The format property on the image will report the image format(e.g png, jpeg), the mode will report the pixel channel format (e.g. This returns an image object that contains the pixel data for the image as well as details about the image. #Load and show an image with PillowĪbove the image is loaded directely using the open() function on Image class. Download the image and save it in your current working directory. ![]() I’ve used the statue_of_unity photo as a sample image. ![]() The easiest way to install it is to use pip: pip install pillow How to load and display imagesįirst we need a test image to demonstrate some important features of using the python Pillow library. Incase of Linux, pillow will probably be there already, since major flavour of linux including Fedora, Debian/Ubuntu and ArchLinux includes Pillow in packages that previously contained PIL. Installing Pillowīefore we start, we need python and pillow. It is also the basis for simple image support in other Python libraries such as sciPy and Matplotlib. Pillow is an updated version of the Python Image Library or PIL and supports a range of simple and advanced image manipulation functionality. One of the most popular and considered as default library of python for image processing is Pillow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |