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
3
votes
2 answers

What's the most efficient way to compute the mode in a sliding window over a 2D array in Python?

I have an RGBA image that I need to upscale while keeping it smooth. The catch is that I need to keep the colors exactly the way they are (background: I'm resizing a map where provinces are color-coded), and so I cannot just perform a resize with…
3
votes
0 answers

Saving JPG format with PIL

I'm using PIL to make thumbnails of images I upload and everything is fine with PNGs or GIFs. However, uploading JPGs is giving me a headache. I kept getting a invalid format type for a while, and then I found this at the bottom of the JPG page on…
captDaylight
  • 2,224
  • 4
  • 31
  • 42
3
votes
4 answers

Installing a Module on Heroku

I'm deploying something that has been running on my local and realized when I deployed that the module I was using wasn't installed on Heroku, thus I was getting an error like this: ... from PIL import Image ImportError: No module named…
captDaylight
  • 2,224
  • 4
  • 31
  • 42
3
votes
1 answer

PIL fromstring error

I have a png picture, and i need to save it as string, and then open it again with PIL. I'm trying to do it like that: output = StringIO.StringIO() old_image.save(output, format="PNG") contents = output.getvalue() output.close() new_image =…
nukl
  • 10,073
  • 15
  • 42
  • 58
3
votes
4 answers

Error in PIL installed with PIP - Django,Python

I installed PIL using PIP. However, using PIL on Django, when trying to upload a .jpg file, I get the error: Upload a valid image. The file you uploaded was either not an image or a corrupted image. I read on the Internet about this error and a…
user1034697
3
votes
3 answers

How do I filter the thick edges of an image?

I am using the Python image library for some basic image operations. I wish to do detect edges of an image, but only the thick ones. How can I do this?
Vishwanath
  • 835
  • 1
  • 7
  • 19
3
votes
1 answer

Google App Engine (So "Pure Python"): Convert PDF to Image

In Google App Engine, I need to be able to take an uploaded PDF and convert it to an image (or maybe one day a number of tiled images) for storing and serving back out. Is there a library that will read PDF files that is also 100% python (so it can…
3
votes
4 answers

python imaging library cannot save PNG to JPG

I installed PIL 1.1.7 from source on Mac OSX. I also installed required libraries from Macports. Using python 2.6. After installing PIL, I could successfully run the selftest.py (all tests pass) But when I try running the following code, I find that…
sunnybythesea
  • 119
  • 1
  • 8
3
votes
1 answer

Image Upload broken on the web, but PIL runs fine in django shell

Not sure exactly what I broke. I have an ubuntu natty linux server, and have several virtualenvs on it. Django image upload was working fine on the dev virtualenv, so it was time to get it working in production. PIL was misbehaving there so I tried…
user573117
  • 91
  • 1
  • 8
3
votes
4 answers

Django OS X Wrong JPEG library version: library is 80, caller expects 62 sorl.thumbnail

Im using sorl.thumbnail for django locally on my mac and have been having trouble with PIL, but today i finally managed to get it installed - was some trouble with libjpeg. I can now upload and use images - but I cant resize them using…
niklasdstrom
  • 742
  • 6
  • 17
3
votes
4 answers

Pixel Loading and Evaluating with PIL

I want to create a program that loads the RGB values of each pixel in a image and saves them in some kind of list/dictionary/tuple and then when I type in a value it tells me how much pixels in the image have that value. So far I have read through…
gandreadis
  • 3,004
  • 2
  • 26
  • 38
3
votes
1 answer

How to adjust the image to meet the minimum requirements and avoid receiving the Telegram API Bad Request error: PHOTO_INVALID_DIMENSIONS?

Summary: Telegram has requirements for images that are sent, and to avoid failures, I add huge white borders far above what would be the minimum necessary. I would like to know how I could create a method so that the image is adjusted at once but…
Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
3
votes
2 answers

Gradient using PIL is just one solid color

I made a little script to create a gradient using python and save it as an image. Here is the code: from PIL import Image, ImageDraw # Define the image size and color gradient width, height = 500, 500 color_start = (255, 0, 0) # red color_end =…
3
votes
1 answer

Is double close in strace necessarily bad?

I am training a neural network. Somewhere in my code base, I have a code snippet like the following: def foo(): d = {} with PIL.Image.open(img_path) as img: d["img"] = torchvision.transforms.functional.to_tensor(img) return…
CrabMan
  • 1,578
  • 18
  • 37
3
votes
1 answer

Why do image size differ when vertical vs horizontal?

Tried to create a random image with PIL as per the example: import numpy from PIL import image a = numpy.random.rand(48,84) img = Image.fromarray(a.astype('uint8')).convert('1') print(len(img.tobytes())) This particular code will output 528. Wen…
1 2 3
99
100