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
165
votes
5 answers

Convert image from PIL to openCV format

I'm trying to convert image from PIL to OpenCV format. I'm using OpenCV 2.4.3. here is what I've attempted till now. >>> from PIL import Image >>> import cv2 as cv >>> pimg = Image.open('D:\\traffic.jpg') #PIL Image >>>…
md1hunox
  • 3,815
  • 10
  • 45
  • 67
153
votes
8 answers

Image library for Python 3

What is python-3 using instead of PIL for manipulating Images?
banx
  • 4,376
  • 4
  • 30
  • 34
153
votes
5 answers

How can I save an image with PIL?

I have just done some image processing using the Python image library (PIL) using a post I found earlier to perform fourier transforms of images and I can't get the save function to work. The whole code works fine but it just wont save the resulting…
user1999274
  • 1,557
  • 2
  • 10
  • 6
147
votes
8 answers

Convert RGBA PNG to RGB with PIL

I'm using PIL to convert a transparent PNG image uploaded with Django to a JPG file. The output looks broken. Source file Code Image.open(object.logo.path).save('/tmp/output.jpg',…
Danilo Bargen
  • 18,626
  • 15
  • 91
  • 127
136
votes
8 answers

How to reduce the image file size using PIL

I am using PIL to resize the images there by converting larger images to smaller ones. Are there any standard ways to reduce the file size of the image without losing the quality too much? Let's say the original size of the image is 100 kB. I want…
Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
135
votes
12 answers

Working with TIFFs (import, export) in Python using numpy

I need a python method to open and import TIFF images into numpy arrays so I can analyze and modify the pixel data and then save them as TIFFs again. (They are basically light intensity maps in greyscale, representing the respective values per…
Jakob
  • 1,897
  • 2
  • 16
  • 17
132
votes
28 answers

Can't install PIL after Mac OS X 10.9

I've just updated my Mac OS to 10.9 and I discovered that some (all?) of my Python modules are not here anymore, especially the Image one. So I try to execute sudo pip install pil, but I get this…
Vincent Audebert
  • 1,846
  • 2
  • 15
  • 28
131
votes
4 answers

Convert PIL Image to byte array?

I have an image in PIL Image format. I need to convert it to byte array. img = Image.open(fh, mode='r') roiImg = img.crop(box) Now I need the roiImg as a byte array.
Evelyn Jeba
  • 4,181
  • 3
  • 12
  • 10
130
votes
5 answers

Get pixel's RGB using PIL

Is it possible to get the RGB color of a pixel using PIL? I'm using this code: im = Image.open("image.gif") pix = im.load() print(pix[1,1]) However, it only outputs a number (e.g. 0 or 1) and not three numbers (e.g. 60,60,60 for R,G,B). I guess I'm…
GermainZ
  • 1,893
  • 3
  • 15
  • 20
126
votes
2 answers

Open PIL image from byte file

I have this image with size 128 x 128 pixels and RGBA stored as byte values in my memory. But from PIL import Image image_data = ... # byte values of the image image = Image.frombytes('RGBA', (128,128), image_data) image.show() throws the…
Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
126
votes
10 answers

Add Text on Image using PIL

I have an application that loads an Image and when the user clicks it, a text area appears for this Image (using jquery), where user can write some text on the Image. Which should be added on Image. After doing some research on it, I figured that…
Apostolos
  • 7,763
  • 17
  • 80
  • 150
123
votes
6 answers

How to write PNG image to string with the PIL?

I have generated an image using PIL. How can I save it to a string in memory? The Image.save() method requires a file. I'd like to have several such images stored in dictionary.
maxp
  • 5,454
  • 7
  • 28
  • 30
117
votes
1 answer

cannot write mode RGBA as JPEG

I am learning to use 'pillow 5.0' following book 'Automate the boring stuff with python' The info about the image object In [79]: audacious = auda In [80]: print(audacious.format, audacious.size, audacious.mode) PNG (1094, 960) RGBA When I tried to…
user9062604
117
votes
8 answers

How to show PIL images on the screen?

I am doing some image editing with the PIL libary. The point is, that I don't want to save the image each time on my HDD to view it in Explorer. Is there a small module that simply enables me to set up a window and display the image?
Bartlomiej Lewandowski
  • 10,771
  • 14
  • 44
  • 75
115
votes
13 answers

"The headers or library files could not be found for jpeg" installing Pillow on Alpine Linux

I'm trying to run Python's Scrapy in a Docker container based on python:alpine. It was working before, but now I'd like to use Scrapy's Image Pipeline which requires me to install Pillow. As a simplified example, I tried the following…
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526