Python Imaging Library Mac

Overview

In last post I was writing about PIL, also known as Python Imaging Library, this library can be used to manipulate images quite easy. PIL hasn't seen any development since 2009. Therefore, the kind users of this site suggested to take a look at Pillow. This article well tell you how to use Pillow.

Python Imaging Library¶ The Python Imaging Library adds image processing capabilities to your Python interpreter. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. The core image library is designed for fast access to data stored in a few basic pixel. Aug 03, 2011  Python Imaging Library. Contribute to whatupdave/pil development by creating an account on GitHub. This source kit has been built and tested with Python 2.0 and newer, on Windows, Mac OS X, and major Unix platforms. Large parts of the library also work on 1.5.2 and 1.6. This course will walk you through a hands-on project suitable for a portfolio. You will be introduced to third-party APIs and will be shown how to manipulate images using the Python imaging library (pillow), how to apply optical character recognition to images to recognize text (tesseract and py-tesseract), and how to identify faces in images using the popular opencv library. The library supports all GNU/Linux distributions, several BSD flavors, as well as the Microsoft Windows and Mac OS X operating systems. It has been successfully tested with both 64-bit and 32-bit hardware platforms. Python imaging Python library PIL fork PIL Python-pillow Imaging Library.

Python is a widely-used programming language used in many of the computer science classes here at St. What is PIL/Pillow? PIL (Python Imaging Library) adds many image processing features to Python. Python Imaging Library (PIL) The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities. Pillow is the friendly PIL fork by Alex Clark and Contributors.PIL is the Python Imaging Library by Fredrik Lundh and Contributors.

What is Pillow?

Imaging

Pillow is a fork of PIL (Python Image Library), started and maintained by Alex Clark and Contributors. It was based on the PIL code, and then evolved to a better, modern and more friendly version of PIL. It adds support for opening, manipulating, and saving many different image file formats. A lot of things work the same way as the original PIL.

Download and Installing Pillow

Before we start to use the Pillow, we must first download and install it. Pillow is available for Windows, Mac OS X and Linux. The most recent version is '2.2.1' and is supported by python 2.6 and above. To install Pillow on Windows machines you can use easy_install:

To install Pillow on Linux machines simply use:

To install Pillow on Mac OS X I had to first install XCode and then install the the prerequisites is via Homebrew. After Homebrew was installed, I ran:

Python imaging library machines

Please let me know if you know an easier way to do this on Mac.

Verify that Pillow is installed

To verify that Pillow is installed, open up a Terminal and type in the following line:

If the system comes back with a '>>>', the Pillow modules are properly installed.

File formats

Before we start using the Pillow module, let us mention some of the filetypes that is supported. BMP EPS GIF IM JPEG MSP PCX PNG PPM TIFF WebP ICO PSD PDF Some of the file types, you only have the possibility to read, and others you can only write. To see the full list of supported file types, and more information about them, take a look at the handbook for Pillow.

How to use Pillow to manipulate an image

Since we are going to work with images, let us first download one. If you already have a picture to use, go ahead and skip this step. In our example we will use a standard test image called 'Lenna' or 'Lena'. That standard test image is used in many image processing experiment. Just go here and download the picture. If you click on the image, it will save it as an 512×512px image.

Using Pillow

Python imaging library api

Let us look at the possible uses for this library. The basic functions are found in the Image module. You can create instances of this class in several ways either by loading images from files, processing other images, or creating images from scratch. Import the Pillow modules you want to use.

You can then access functions as usual, e.g.

Load an Image

To load an image from your computer, you can use use 'open' method to identify the file, and then load the identified file using myfile.load(). Once the image is loaded, you can do a number of things with it. I often use the try/except block when dealing with files. To load our image using try/except:

When we read files from disk using the open() function, we don't have to know the format of the file to. The library automatically determines the format based on the contents of the file. Now when you have an Image object, you can use the available attributes to examine the file. For example, if you want to see the size of the image, you can call the 'format' attribute.

The 'size' attribute is a 2-tuple containing width and height (in pixels). Common 'modes' are 'L' for greyscale images, 'RGB' for true color images, and 'CMYK' for pre-press images. The output of above should give you this:

Blur an Image

This example will load an image from the hard drive and blurs it. [source]

The blurred image should look like this:
To display the image, we used the 'show()' methods. If you don't see anything, you could try installing ImageMagick first and run the example again.

Creating Thumbnails

A very common thing to do is creating thumbnails for images. Thumbnails are reduced-size versions of pictures but still contains all of the most important aspects of an image.

The result of our program, showing the thumbnail:

Python Imaging Library Mac Os

Filters in Pillow

The Pillow module provides the following set of predefined image enhancement filters:

In our last example for today, we will show how you can apply the 'contour' filter to your image. The code below will take our image and apply

Our image with the 'contour' filter applied:
I enjoyed to try out Pillow, and I will write more posts about it in the future.

More Reading

Share this article

Install Python Imaging Library

Recommended Python Training – DataCamp

For Python training, our top recommendation is DataCamp.

Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.

Datacamp has beginner to advanced Python training that programmers of all levels benefit from.


Read more about:

Python Imaging Library Machine

Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, PythonForBeginners.com only recommend products or services that we try personally and believe will add value to our readers.

Python Imaging Library Mac Torrent

Categories