![]() Height: The height of the image in pixels Size: The image size in pixels displayed as a width, height tuple Mode: The image mode such as RGB, RFBA, CMYK, or YCbCr In addition to showing an image, the Image class provides a number of other properties and methods that can be used with images. The following shows the image being displayed on a Windows system: If you run Listing 1 in a directory that contains an image named image.jpg, the image will be displayed. With the image loaded, you are ready to display the image by calling the show() method on your image variable. With the library loaded, you can load an image by call in the Image.open() method and assign the return value to a variable. The code in listing 1 starts by importing the Image library. ![]() Listing 1: Img.py: Loading an Image in Python from PIL import Image Writing an application to display an image in Python can be done with just a couple of lines of code as shown in Listing 1: Loading and Displaying an Image in Python Once you’ve installed Pillow, you are ready to start working with images. This will install an updated version of the Python Image Library (PIL), which will allow you to load and use images. Installing the Pillow module can be done using the simple command line directive of: pip install pillow Additionally, you will want to make sure you have the Pillow module installed. Of course, to use images in Python, you need to have Python installed. We’ll show how to load and display an image using Python, how to get image information using Python, and how to convert image formats using Python. To illustrate how easy some things are to do in Python, we’ll take a quick look at working with images. Most importantly, however, is that Python is simple to code and very readable. ![]() It is both object-oriented and procedural, it’s open-sourced and extensible, it’s portable, and it has library support. It’s gained that popularity for a variety of reasons. Python is gaining more attention and attraction than most other programming languages today. We may make money when you click on links to our partners. content and product recommendations are editorially independent.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |