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.
python-imaging-library
10,058
questions
635
votes
25
answers
1.2m
views
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.
476
votes
9
answers
899k
views
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(&...
446
votes
7
answers
603k
views
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?
390
votes
21
answers
1.1m
views
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 ...
369
votes
31
answers
1.4m
views
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 "<console>", line ...
314
votes
15
answers
491k
views
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 ...
305
votes
15
answers
159k
views
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)
...
280
votes
3
answers
594k
views
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 ...
243
votes
8
answers
230k
views
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 ...
219
votes
12
answers
322k
views
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 ...
209
votes
13
answers
299k
views
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 ...
203
votes
4
answers
277k
views
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?
181
votes
18
answers
316k
views
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
<module 'scipy....
180
votes
13
answers
121k
views
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:...
179
votes
10
answers
266k
views
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?
170
votes
5
answers
279k
views
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 =...
159
votes
5
answers
463k
views
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 ...
153
votes
8
answers
177k
views
Image library for Python 3
What is python-3 using instead of PIL for manipulating Images?
149
votes
8
answers
226k
views
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', 'JPEG')
or
...
142
votes
8
answers
244k
views
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 ...
137
votes
12
answers
395k
views
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 ...
136
votes
11
answers
267k
views
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.
...
134
votes
2
answers
213k
views
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,...
134
votes
4
answers
186k
views
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.
132
votes
28
answers
94k
views
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 ...
132
votes
5
answers
295k
views
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 ...
129
votes
1
answer
139k
views
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, ...
125
votes
6
answers
142k
views
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.
122
votes
11
answers
109k
views
Center-/middle-align text with PIL?
How would I center-align (and middle-vertical-align) text when using PIL?
120
votes
13
answers
121k
views
"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 ...
119
votes
8
answers
347k
views
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 ...
115
votes
6
answers
138k
views
How do you composite an image onto another image with PIL in Python?
I need to take an image and place it onto a new, generated white background in order for it to be converted into a downloadable desktop wallpaper. So the process would go:
Generate new, all white ...
107
votes
7
answers
130k
views
PIL "IOError: image file truncated" with big images
I think this problem is not Zope-related. Nonetheless I'll explain what I'm trying to do:
I'm using a PUT_factory in Zope to upload images to the ZODB per FTP. The uploaded image is saved as a Zope ...
101
votes
11
answers
145k
views
How to use PIL to make all white pixels transparent?
I'm trying to make all white pixels transparent using the Python Image Library. (I'm a C hacker trying to learn python so be gentle)
I've got the conversion working (at least the pixel values look ...
98
votes
5
answers
82k
views
Getting "cannot write mode P as JPEG" while operating on JPG image
I am trying to resize some images, most of which are JPG. But in a few images, I am getting the error:
Traceback (most recent call last):
File "image_operation_new.py", line 168, in modifyImage
...
94
votes
6
answers
253k
views
Using PIL to turn a RGB image into a pure black and white image
I'm using the Python Imaging Library for some very simple image manipulation, however I'm having trouble converting a greyscale image to a monochrome (black and white) image. If I save after changing ...
93
votes
4
answers
154k
views
Convert png to jpeg using Pillow
I am trying to convert png to jpeg using pillow. I've tried several scrips without success. These 2 seemed to work on small png images like this one.
First code:
from PIL import Image
import os, sys
...
92
votes
4
answers
159k
views
Convert opencv image format to PIL image format?
I want to convert an image loaded
TestPicture = cv2.imread("flowers.jpg")
I would like to run a PIL filter like on the example with the variable
TestPicture
but I'm unable to convert it ...
92
votes
12
answers
113k
views
Multiplying a tuple by a scalar
I have the following code:
print(img.size)
print(10 * img.size)
This will print:
(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
I'd like it to print:
(700, ...
91
votes
6
answers
169k
views
PIL TypeError: Cannot handle this data type
I have an image stored in a numpy array that I want to convert to PIL.Image in order to perform an interpolation only available with PIL.
When trying to convert it through Image.fromarray() it raises ...
90
votes
7
answers
124k
views
Resampling a numpy array representing an image
I am looking for how to resample a numpy array representing image data at a new size, preferably having a choice of the interpolation method (nearest, bilinear, etc.). I know there is
scipy.misc....
89
votes
2
answers
60k
views
how to save a pylab figure into in-memory file which can be read into PIL image?
The following is my first shot which never works:
import cStringIO
import pylab
from PIL import Image
pylab.figure()
pylab.plot([1,2])
pylab.title("test")
buffer = cStringIO.StringIO()
pylab....
88
votes
16
answers
165k
views
ImportError: cannot import name _imaging
I installed Pillow, and after I want to do:
from PIL import Image
I get the following error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/...
87
votes
14
answers
54k
views
PIL thumbnail is rotating my image?
I'm attempting to take large (huge) images (from a digital camera), and convert them into something that I can display on the web. This seems straightforward, and probably should be. However, when I ...
83
votes
3
answers
149k
views
Get error when try to install PIL [duplicate]
I try to install PIL but get errors, what should I do?
$ Command
Result
------------
$ pip install PIL
Collecting PIL
Could not find a version that satisfies the requirement PIL (from versions: )
...
83
votes
6
answers
153k
views
PIL cannot write mode F to jpeg
I am taking a jpg image and using numpy's fft2 to create/save a new image. However it throws this error
"IOError: cannot write mode F as JPEG"
Is there an issue with CMYK and JPEG files in PIL???
...
81
votes
17
answers
94k
views
Python: The _imagingft C module is not installed
I've tried lots of solution that posted on the net, they don't work.
>>> import _imaging
>>> _imaging.__file__
'C:\\python26\\lib\\site-packages\\PIL\\_imaging.pyd'
>>>
So ...
80
votes
19
answers
285k
views
Why can't Python import Image from PIL?
The single line that I am trying to run is the following:
from PIL import Image
However simple this may seem, it gives an error:
Traceback (most recent call last):
File "C:\...\2014-10-22_12-49....
78
votes
14
answers
146k
views
PIL rotate image colors (BGR -> RGB)
I have an image where the colors are BGR. How can I transform my PIL image to swap the B and R elements of each pixel in an efficient manner?
78
votes
2
answers
115k
views
How do I close an image opened in Pillow?
I have a python file with the Pillow library imported. I can open an image with
Image.open(test.png)
But how do I close that image? I'm not using Pillow to edit the image, just to show the image and ...