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
1 answer

I want to display urdu text on image using python

from PIL import Image, ImageFont, ImageDraw from matplotlib import pyplot as plt import numpy as np import cv2 text_string = u'تصوير' img = Image.new('RGB', (200, 150)) draw = ImageDraw.Draw(img) font = ImageFont.truetype('C:\\Windows\\Nafees…
fatima
  • 31
  • 2
3
votes
0 answers

How to refer to unreferenced HTML elements with selenium in Python

I am trying to use the python selenium web-driver to locate the tile/button elements for googles minesweeper game, but they do not appear as individual HTML elements that can be referenced when inspected. I can reference the element containing the…
3
votes
2 answers

How to generate a PNG image in PIL and display it in Jinja2 template using FastAPI?

I have a FastAPI endpoint that is generating PIL images. I want to then send the resulting image as a stream to a Jinja2 TemplateResponse. This is a simplified version of what I am doing: import io from PIL import Image @api.get("/test_image",…
Brad Allen
  • 245
  • 3
  • 9
3
votes
1 answer

PIL Writing Text on Image Using Escape Sequence

`from PIL import Image, ImageDraw, ImageFont image = Image.new('RGB', (950, 250), color=(255, 255, 255)) TEXT = 'You are a wondeful \033[32mperson.' font_size = 50 font_type = "SourceCodePro-Bold.ttf" draw = ImageDraw.Draw(im=image) font =…
P. Roy
  • 31
  • 4
3
votes
0 answers

Pillow cannot extract all exif information

I am trying to use Pillow to get exif data for photos, but it looks like it does not return all that should be available. Using the simple code: from PIL import Image from PIL.ExifTags import TAGS def get_exif(): i = Image.open('IMG_0780.JPG') …
Asara
  • 2,791
  • 3
  • 26
  • 55
3
votes
1 answer

Convert cmap values to RGB for PIL.Image

I want to use PIL.Image to save a figure and I want to use matplotlib cmaps to map the data to a color. I have tried the following: import matplotlib matplotlib.use('TkAgg') import matplotlib as mpl import matplotlib.pyplot as plt from matplotlib…
Tom McLean
  • 5,583
  • 1
  • 11
  • 36
3
votes
1 answer

Get number of layers in tif image using python

I have the tif image with 5 layers (not color channels but layers). How can I get the number of layers in this tif file using python? I tried PIL.Image im.n_frames and cv2.imreadmulti they all show that image has only one layer.
Yuriki
  • 33
  • 4
3
votes
1 answer

Percentage of green & white pixels in each row

I have an input image as given below. enter image description here I need to get total percentage and count of green and white pixels in each row of image with specific rowwise as output. I have tried code for getting percentage and count for single…
3
votes
2 answers

Colors in pillow-generated image viewed in tkinter don't match colors in saved file

I wrote a Python script that fuses a stereo pair of images into an anaglyph image. When I view the image in a tkinter application I wrote the image looks good but when I save as a JPG and PNG to Photoshop it looks "confused". For a while I was…
Paul Houle
  • 51
  • 5
3
votes
0 answers

cv2_imshow return PIL object instead of display image on Colab

I am facing a problem in displaying image on Colab. The code that I run is in .py file which I run on Colab, so in that file I have import cv2_imshow instead of normal cv2 and called it in a file. from google.colab.patches import cv2_imshow When I…
3
votes
1 answer

A buffer which shows in pygame does not display in tkinter

The code below illustrates a buffer which displays with pygame.image.frombuffer but not with tkinter PhotoImage import chess, chess.svg, pylunasvg as pl from tkinter import Tk, PhotoImage # This is where I create the buffer board =…
3
votes
1 answer

Subtract 16 bit tiff image in python

I have two 16 bit tiff image, of which one is a background and I have to remove it from all the image. I use the following code, however I get the error saying return image1._new(image1.im.chop_difference(image2.im)) ValueError: image has wrong…
3
votes
2 answers

How to combine PIL and cairosvg to create pattern from svg?

I was wondering if would be possible to load a svg format like shape and with loop to repeat with for loop to get some kind a generic pattern. Most what I have founded researching online, is to convert from svg to png or some else format but I was…
Firefoxer
  • 265
  • 3
  • 15
3
votes
2 answers

Pillow - draw a literal tag glyph?

The Unifont contains glyphs for Tags, Variation Selectors, and other non-printable characters. For example at the end of https://unifoundry.com/pub/unifont/unifont-14.0.04/font-builds/unifont_upper-14.0.04.ttf are these tags (as shown in…
Terence Eden
  • 14,034
  • 3
  • 48
  • 89
3
votes
1 answer

Raspbian-Python3.9: ImportError: The _imagingft C module is not installed

I'm trying to run a simple code using PIL with custom fonts in Python3.9 in Raspbian, but i can't go past this error: Traceback (most recent call last): File "/home/pi/python/src/mintest.py", line 2, in font52 =…
driconmax
  • 956
  • 1
  • 18
  • 32
1 2 3
99
100