Questions tagged [python-imaging-library]

The Python Imaging Library (PIL) provides the Python language with a de-facto standard foundation for image work. PIL’s API is lightweight but semantically consistent; it furnishes a range of comfortably Pythonic tools throughout much of the imaging lexicon: processing, analysis, compression and codec abstraction, etc. – all of which builds upon a bespoke and readily extensible library structure.

The Python Imaging Library (PIL) provides the Python language with a de-facto standard foundation for image work.

PIL’s API is lightweight but semantically consistent. It furnishes a range of comfortably Pythonic tools, whose top-level hierarchy covers a broad lexical range of the imaging fields’ usual suspects, including: pixel and channel processing; statistical analysis; affine, Gaussian, and kernel transforms, abstraction for compressors, binary formats, codecs, and the like; vector drawing and typesetting; pixel mathematics and color correction; matrices; programming and I/O paradigms. Each of these is notionally organized into a Python sub-package and implemented with an API in a mode whose form is germane to its concept – e.g. while the IO modules like PIL.Image and PIL.ImageFile generally follow along with the Python standard libraries — they employ OO-style conventions that very similar throughout – PIL is not pedantic in this way, as other submodules are non-uniform when they need to be… PIL.ImageFilter, for example, is written in a functional style (obfuscated slightly, due to having been CamelCased). And PIL.ImageMath exposes its interface as a little subset of Python language itself, with which the programmer can tersely and legibly describe an algorithm – which PIL can then take and deterministically pipeline and vectorize into something much faster than naïve Python.However, it only supports Python 1.5.2 and newer, including 2.5 and 2.6.

More information can be found at PIL (PythonWare.com); founded and first developed by Fredrik Lundh, the original PIL codebase is open source, but unmaintained since 2011.

There is also an active, maintained and popular fork of PIL called Pillow which releases quarterly with security updates, new features and bug fixes, it supports python 3.x.

9873 questions
622
votes
23 answers

How do I resize an image using PIL and maintain its aspect ratio?

Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails.
saturdayplace
  • 8,370
  • 8
  • 35
  • 39
463
votes
9 answers

How do I convert a PIL Image into a NumPy array?

How do I convert a PIL Image back and forth to a NumPy array so that I can do faster pixel-wise transformations than PIL's PixelAccess allows? I can convert it to a NumPy array via: pic = Image.open("foo.jpg") pix =…
akdom
  • 32,264
  • 27
  • 73
  • 79
433
votes
7 answers

How do I get the picture size with PIL?

How do I get a size of a pictures sides with PIL or any other Python library?
I159
  • 29,741
  • 31
  • 97
  • 132
391
votes
21 answers

How to install PIL with pip on Mac OS?

I am trying to install PIL (the Python Imaging Library) using the command: sudo pip install pil but I get the following message: Downloading/unpacking PIL You are installing a potentially insecure and unverifiable file. Future versions of pip…
user3006710
  • 3,947
  • 2
  • 12
  • 3
352
votes
30 answers

ImportError: No module named PIL

I use this command in the shell to install PIL: easy_install PIL then I run python and type this: import PIL. But I get this error: Traceback (most recent call last): File "", line 1, in ImportError: No module named PIL I've…
Asma Gheisari
  • 5,794
  • 9
  • 30
  • 51
306
votes
15 answers

Python Image Library fails with message "decoder JPEG not available" - PIL

PIL does support JPEG in my system. Whenever I do an upload, my code is failing with: File "PIL/Image.py", line 375, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder jpeg not available How can I resolve…
Ravi
  • 2,472
  • 3
  • 20
  • 26
303
votes
15 answers

How do I read image data from a URL in Python?

What I'm trying to do is fairly simple when we're dealing with a local file, but the problem comes when I try to do this with a remote URL. Basically, I'm trying to create a PIL image object from a file pulled from a URL. Sure, I could always just…
Daniel Quinn
  • 6,010
  • 6
  • 38
  • 61
270
votes
3 answers

How to convert a NumPy array to PIL image applying matplotlib colormap

I have a simple problem, but I cannot find a good solution to it. I want to take a NumPy 2D array which represents a grayscale image, and convert it to an RGB PIL image while applying some of the matplotlib colormaps. I can get a reasonable PNG…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
238
votes
8 answers

How to merge a transparent png image with another image using PIL

I have a transparent png image foo.png and I've opened another image with: im = Image.open("foo2.png") Now what I need is to merge foo.png with foo2.png. (foo.png contains some text and I want to print that text on foo2.png)
Arackna
  • 2,665
  • 2
  • 16
  • 16
205
votes
13 answers

Combine several images horizontally with Python

I am trying to horizontally combine some JPEG images in Python. Problem I have 3 images - each is 148 x 95 - see attached. I just made 3 copies of the same image - that is why they are the same. My attempt I am trying to horizontally join them…
edesz
  • 11,756
  • 22
  • 75
  • 123
203
votes
12 answers

How to show PIL Image in ipython notebook

This is my code from PIL import Image pil_im = Image.open('data/empire.jpg') I would like to do some image manipulation on it, and then show it on screen. I am having problem with showing PIL Image in python notebook. I have tried: print…
WebOrCode
  • 6,852
  • 9
  • 43
  • 70
196
votes
4 answers

How to crop an image using PIL?

I want to crop image in the way by removing first 30 rows and last 30 rows from the given image. I have searched but did not get the exact solution. Does somebody have some suggestions?
Taj Koyal
  • 2,023
  • 2
  • 13
  • 3
179
votes
13 answers

Fail during installation of Pillow (Python module) in Linux

I'm trying to install Pillow (Python module) using pip, but it throws this error: ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting So as the error says, I tried: pip install pillow…
mchfrnc
  • 5,243
  • 5
  • 19
  • 37
179
votes
18 answers

scipy.misc module has no attribute imread?

I am trying to read an image with scipy. However it does not accept the scipy.misc.imread part. What could be the cause of this? >>> import scipy >>> scipy.misc >>>…
ustroetz
  • 5,802
  • 16
  • 47
  • 74
172
votes
10 answers

In Python, how do I read the exif data for an image?

I'm using PIL. How do I turn the EXIF data of a picture into a dictionary?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
1
2 3
99 100