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.

7275 questions
512
votes
21 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
  • 7,240
  • 8
  • 31
  • 38
386
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,897
  • 2
  • 10
  • 3
333
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
  • 24,762
  • 27
  • 88
  • 124
324
votes
8 answers

How to convert a PIL Image into a numpy array?

Alright, I'm toying around with converting a PIL image object back and forth to a numpy array so I can do some faster pixel by pixel transformations than PIL's PixelAccess object would allow. I've figured out how to place the pixel information in a…
akdom
  • 28,041
  • 24
  • 70
  • 79
304
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,432
  • 3
  • 15
  • 25
254
votes
25 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
  • 4,564
  • 7
  • 27
  • 47
222
votes
12 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
  • 4,647
  • 3
  • 31
  • 50
183
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
  • 23,225
  • 20
  • 121
  • 212
178
votes
7 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,065
  • 2
  • 14
  • 16
154
votes
8 answers

Image library for Python 3

What is python-3 using instead of PIL for manipulating Images?
banx
  • 4,058
  • 4
  • 22
  • 31
149
votes
15 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
  • 4,962
  • 13
  • 39
  • 69
148
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
  • 1,535
  • 2
  • 9
  • 3
145
votes
11 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
  • 8,579
  • 17
  • 58
  • 103
143
votes
9 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
  • 217,272
  • 324
  • 727
  • 1,038
137
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
  • 5,602
  • 7
  • 35
  • 62
1
2 3
99 100