
- Python Pillow - Home
- Python Pillow - Overview
- Python Pillow - Environment Setup
- Basic Image Operations
- Python Pillow - Working with Images
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Adding Borders to Images
- Python Pillow - Identifying Image Files
- Python Pillow - Merging Images
- Python Pillow - Cutting and Pasting Images
- Python Pillow - Rolling an Image
- Python Pillow - Writing text on image
- Python Pillow - ImageDraw Module
- Python Pillow - Concatenating two Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Creating a Watermark
- Python Pillow - Image Sequences
- Python Pillow Color Conversions
- Python Pillow - Colors on an Image
- Python Pillow - Creating Images With Colors
- Python Pillow - Converting Color String to RGB Color Values
- Python Pillow - Converting Color String to Grayscale Values
- Python Pillow - Change the Color by Changing the Pixel Values
- Image Manipulation
- Python Pillow - Reducing Noise
- Python Pillow - Changing Image Modes
- Python Pillow - Compositing Images
- Python Pillow - Working with Alpha Channels
- Python Pillow - Applying Perspective Transforms
- Image Filtering
- Python Pillow - Adding Filters to an Image
- Python Pillow - Convolution Filters
- Python Pillow - Blur an Image
- Python Pillow - Edge Detection
- Python Pillow - Embossing Images
- Python Pillow - Enhancing Edges
- Python Pillow - Unsharp Mask Filter
- Image Enhancement and Correction
- Python Pillow - Enhancing Contrast
- Python Pillow - Enhancing Sharpness
- Python Pillow - Enhancing Color
- Python Pillow - Correcting Color Balance
- Python Pillow - Removing Noise
- Image Analysis
- Python Pillow - Extracting Image Metadata
- Python Pillow - Identifying Colors
- Advanced Topics
- Python Pillow - Creating Animated GIFs
- Python Pillow - Batch Processing Images
- Python Pillow - Converting Image File Formats
- Python Pillow - Adding Padding to an Image
- Python Pillow - Color Inversion
- Python Pillow - M L with Numpy
- Python Pillow with Tkinter BitmapImage and PhotoImage objects
- Image Module
- Python Pillow - Image Blending
- Python Pillow Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - Function Reference
- Python Pillow - Useful Resources
- Python Pillow - Discussion
Python Pillow - Converting Image File Formats
Converting image file formats with Python Pillow is a straightforward process. You can open an image in one format and save it in another, specifying the desired output format. This process typically involves the following steps −
Open the Source Image: Use the Image.open() function to open the source image.
Save the Image: Use the save() method to save the image in the desired format, specifying the new file format and destination.
Pillow can recognize and read over 30 different formats. When using the open() function, Pillow determines the format based on the image content, not just the file name. However, when saving images with the save() method, it usually looks at the file name to decide the format unless you specifically tell which format to use.
Pillow Supported File Formats
Pillow supports various image formats for both reading and writing. Some formats are fully supported, meaning you can both read from and write to images in those formats. These include popular formats like JPEG, PNG, BMP, BLP, DDS, EPS, GIF, ICNS, ICO, MSP, PCX, PNG, PPM, SGI, TGA, TIFF, WebP, and XBM.
Additionally, it provides read-only and write-only support for a range of other formats.
- Read-Only Formats: CUR, DCX, FITS, FLI, FLC, FPX, GBR, GD, IMT, IPTC/NAA, MCIDAS, MIC, MPO, PCD, PIXAR, PSD, QOI, SUN, WAL, and WMF/EMF.
- Write-Only Formats: PALM, PDF, and XV Thumbnails.
The library can also identify the format of images in formats such as BUFR, GRIB, HDF5, and MPEG. Let's see the exmaples of converting image file formats with Python Pillow.
Example
This example converts the image from JPEG to PNG format.
from PIL import Image # Open the source image in JPEG format image = Image.open("Images/logo.jpg") # Convert and save the image in PNG format image.save("output_image_PNG_format.png") print("Image saved successfully in PNG format...")
Output
Image saved successfully in PNG format...
Example
This example converts the image from BMP to GIF format.
from PIL import Image # Open the source image in BMP format image = Image.open("Images/lena.bmp") # Convert and save the image in GIF format image.save("output_image.gif") print("Image saved successfully in GIF format...")
Output
Image saved successfully in GIF format...
Example
This example converts the image from GIF to TIFF format.
from PIL import Image # Open the source image in GIF format image = Image.open("Images/Book_Animation.gif") # Convert and save the image in TIFF format image.save("output_image.tiff") print("Image saved successfully in TIFF format...")
Output
Image saved successfully in TIFF format...
Example
This example converts the image from .bpm file format to .jpg format.
from PIL import Image # Open the source image in BMP format image = Image.open("Images/lena.bmp") # Convert and save the image in JPEG format image.save('lena_new.jpg') print("Image saved successfully in JPEG format...")
Output
Image saved successfully in JPEG format...
If you visit the folder where the output images are saved you can observe resultant images.