HOME

TheInfoList



OR:

Python Imaging Library is a
free and open-source Free and open-source software (FOSS) is software available under a Software license, license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term ...
additional
library A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
for the
Python programming language Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically type-checked and garbage-collected. It supports multiple prog ...
that adds support for opening, manipulating, and saving many different
image file formats An image file format is a file format for a digital image. There are many formats that can be used, such as JPEG, PNG, and GIF. Most formats up until 2022 were for storing 2D images, not 3D ones. The data stored in an image file format may be c ...
. It is available for
Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
, and
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
. The latest version of PIL is 1.1.7, was released in September 2009 and supports Python 1.5.2–2.7. Development of the original project, known as PIL, was discontinued in 2011. Subsequently, a successor project named Pillow forked the PIL repository and added Python 3.x support. This fork has been adopted as a replacement for the original PIL in
Linux distribution A Linux distribution, often abbreviated as distro, is an operating system that includes the Linux kernel for its kernel functionality. Although the name does not imply product distribution per se, a distro—if distributed on its own—is oft ...
s including
Debian Debian () is a free and open-source software, free and open source Linux distribution, developed by the Debian Project, which was established by Ian Murdock in August 1993. Debian is one of the oldest operating systems based on the Linux kerne ...
and
Ubuntu Ubuntu ( ) is a Linux distribution based on Debian and composed primarily of free and open-source software. Developed by the British company Canonical (company), Canonical and a community of contributors under a Meritocracy, meritocratic gover ...
(since 13.04).


Capabilities

PIL offers several standard procedures for image manipulation. These include: * per-pixel manipulations, * masking and transparency handling, * image filtering, such as blurring, contouring, smoothing, or edge finding, * image enhancing, such as sharpening, adjusting brightness, contrast or color, * adding text


File formats

Supported file formats include PPM, PNG,
JPEG JPEG ( , short for Joint Photographic Experts Group and sometimes retroactively referred to as JPEG 1) is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degr ...
,
GIF The Graphics Interchange Format (GIF; or , ) is a Raster graphics, bitmap Image file formats, image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite and released ...
,
TIFF Tag Image File Format or Tagged Image File Format, commonly known by the abbreviations TIFF or TIF, is an image file format for storing raster graphics images, popular among graphic artists, the publishing industry, and photographers. TIFF is w ...
, and BMP. PIL is extensible, allowing users to create custom decoders for any file format.


Programming examples

import os from PIL import Image def convert_jpegs_to_pngs(folder_path): # Checks if the provided path is a folder if not os.path.isdir(folder_path): print(f"Error: is not a valid folder.") return # Iterates over all files in the folder for filename in os.listdir(folder_path): # Checks if the file has a .jpg or .jpeg extension if filename.lower().endswith(".jpg") or filename.lower().endswith(".jpeg"): # Full path of the file jpeg_path = os.path.join(folder_path, filename) # Path for the converted file png_path = os.path.join(folder_path, os.path.splitext(filename) + ".png") try: # Opens the JPEG image with Image.open(jpeg_path) as img: # Converts and saves as PNG img.save(png_path, "PNG") print(f"Converted to ") except Exception as e: print(f"Error converting : ")


References


External links

*
PIL Library reference
*{{wikibooks-inline, Python Imaging Library
Pillow (Successor project)PIL Tutorial Examples
Graphics libraries Python (programming language) libraries