Documentation Menu

Image File Formats

Pillow supports a wide variety of raster file formats. Over 30 different file formats can be identified and read by the library.

FormatReadWriteNotes
JPEG / JPGLossy. No alpha. Most common photo format.
PNGLossless with alpha. Best for UI / screenshots.
GIFAnimated. 256-colour palette only.
WebPLossy/lossless, animated. Best web compression.
TIFF / TIFMulti-page, raw, high-quality. Used in print/medical.
BMPUncompressed raster. Windows bitmap.
ICOWindows icon format with multiple sizes.
PDFCan write images as PDF pages. Read not supported.
EPS / PS✅ *Requires Ghostscript for reading.
SVG✅ *Read via Wand or extra plugins. Pillow core = no.
HEIC / HEIF✅ *✅ *Requires pillow-heif plugin package.
PPM / PBM / PGMPortable bitmap formats (Unix legacy).
TGATarga format. Common in 3D/game pipelines.
PCXZSoft PC Paintbrush.
SGI / RGBSilicon Graphics Image format.
DDSDirectDraw Surface — used in DirectX games.
AVIF✅ *✅ *Requires pillow-avif-plugin.
XBMX11 bitmap format.
SPIDERSPIDER image format (data visualization).
IMLabEye IM format.

* = Requires optional dependency or plugin

JPEG

JPEG is the most common format for photographs. It uses lossy compression that significantly reduces file size but cannot store alpha transparency. The JPEG/JFIF format supports RGB, L, and CMYK modes.

JPEG Save Options
img.save("output.jpg", quality=85, # 1-95. 85 is good balance. 95 is near-lossless. progressive=True, # Progressive JPEG for web optimize=True, # Huffman table optimization subsampling=2, # Chroma subsampling: 0=4:4:4, 1=4:2:2, 2=4:2:0 dpi=(72, 72) # Set DPI metadata )
Warning: JPEG does not support transparency. If you try to save an RGBA image as JPEG, Pillow raises an OSError. Always convert("RGB") first.

PNG

PNG is a lossless format supporting transparency. It supports modes 1, L, P, RGB, and RGBA. PNG files contain a series of chunks — Pillow exposes most of these via the info dictionary.

PNG Save Options
img.save("output.png", compress_level=6, # 0 (no compression) to 9 (max). Default: 6 optimize=True, # Find optimal compression settings pnginfo=meta # Pass PngInfo object for metadata chunks ) # Add metadata chunks to PNG from PIL.PngImagePlugin import PngInfo meta = PngInfo() meta.add_text("Author", "Pillow Python") img.save("output.png", pnginfo=meta)

GIF

GIF supports animation and transparency but is limited to 256 colours per frame. Pillow reads and writes GIF files, including animated ones.

Animated GIF Save
frames[0].save( "animation.gif", save_all=True, append_images=frames[1:], duration=80, # ms per frame loop=0, # 0 = loop forever disposal=2, # 2 = restore background between frames transparency=0 # transparent colour index in palette )

WebP

WebP provides both lossy and lossless compression with support for transparency and animation. It generally achieves 25-35% smaller files than JPEG at the same visual quality, making it the recommended format for modern web images.

WebP Save Options
img.save("output.webp", quality=85, # 0-100 for lossy lossless=False, # True = lossless mode method=6 # Compression method 0-6. 6=slowest/best ) # Animated WebP frames[0].save( "animation.webp", save_all=True, append_images=frames[1:], duration=80 )

TIFF

TIFF is a flexible raster format widely used in print, medical imaging, and GIS industries. Pillow supports multi-page TIFF and a variety of compression options.

TIFF Save Options
img.save("output.tiff", compression="tiff_lzw", # Options: None, "tiff_deflate", "tiff_lzw", "jpeg" dpi=(300, 300) ) # Multi-page TIFF pages[0].save( "multipage.tiff", save_all=True, append_images=pages[1:] )

BMP

BMP is the native Windows bitmap format. It stores uncompressed image data and supports a wide range of pixel depths (1, 4, 8, 16, 24, 32 bit). Modes: 1, L, P, RGB. Writing is limited to these modes.

ICO (Windows Icon)

ICO files contain multiple image sizes in a single file. Pillow can read and write ICO files, embedding multiple sizes.

ICO Multi-size
img = Image.open("icon_256.png") img.save("favicon.ico", sizes=[(16,16),(32,32),(48,48),(256,256)])

PDF

Pillow can save images as single-page or multi-page PDF documents. Reading PDFs is not supported in Pillow core — use PyPDF2 or mupdf for that.

Save as PDF
# Single page img.save("output.pdf") # Multi-page PDF from list of images images[0].save( "document.pdf", save_all=True, append_images=images[1:] )

EPS / PS (PostScript)

Pillow can write EPS format and can read it if Ghostscript is installed. Ghostscript must be on the system path for rasterization of EPS to work.

SVG (Read-Only via Plugins)

Pillow's core does not support SVG. To render SVG files with Pillow, use a third-party library such as cairosvg, svglib, or Wand (ImageMagick binding) to first convert the SVG to PNG, then open it in Pillow.

SVG → PNG via cairosvg
import cairosvg, io from PIL import Image png_bytes = cairosvg.svg2png(url="icon.svg", output_width=512) img = Image.open(io.BytesIO(png_bytes))

HEIC / HEIF (via plugin)

HEIC is Apple's default photo format since iOS 11. Pillow supports it through the pillow-heif plugin.

HEIC Support
$ pip install pillow-heif import pillow_heif from PIL import Image pillow_heif.register_heif_opener() # Register decoder globally img = Image.open("photo.heic") img.save("photo.jpg", quality=90)

Other Supported Formats

FormatExtensionNotes
PPM / PBM / PGM / PNM.ppm .pbm .pgm .pnmPortable Any Map. Simple uncompressed formats.
TGA / TARGA.tga .vda .icb .vstTarga image. No magic number — extension-based detection.
PCX.pcxZSoft PC Paintbrush. Modes: 1, L, P, RGB.
SGI.sgi .rgb .bwSilicon Graphics native format.
DDS.ddsDirectDraw Surface. Used in DirectX/OpenGL games.
IM.imLabEye IM format.
XBM.xbmX11 bitmap. Mode: 1 only.
XPM.xpmX11 colour pixmap. Read only.
FITS.fits .fit .ftsNASA Flexible Image Transport System. Scientific imagery.
JPEG 2000.jp2 .j2k .jpf .j2cWavelet compression JPEG successor. Modes: L, RGB, RGBA.
PSD.psdAdobe Photoshop. Read only, flattened.
DCX.dcxIntel FAX format (multipage PCX).
MSP.mspWindows 1.x/2.x Paint. Mode: 1 only.