PYTHON HELP

imageio python (How it Works for Developers)

Chaknith Bin
Chaknith Bin
April 17, 2025
Share:

Introduction

Imageio is a versatile Python library designed for reading and writing a wide range of image data, including animated images, volumetric data, and scientific formats. It provides a simple and consistent API, making it an excellent choice for developers and data scientists working with image data processing tasks. In this article, we will look into how Imageio can be used to read and write images, later we will also look into IronPDF from Iron Software to generate PDF documents. Both these packages can be used to create pictures and store images in PDF documents for archiving purposes.

Why Use Imageio?

Imageio offers several advantages:

  1. Wide Format Support: It supports numerous image formats, including PNG, JPEG, GIF, TIFF, and more.
  2. Ease of Use: The API is straightforward to use, even for beginners.
  3. Cross-Platform Compatibility: Imageio works on various operating systems, including Windows, macOS, and Linux.
  4. Integration with other libraries: It can be used alongside other Python libraries like NumPy and Matplotlib for advanced image processing and visualization.

Getting Started with Imageio

Installation

You can install Imageio using pip:

pip install imageio

Basic Usage

Here’s a simple example to demonstrate how to read and write images using Imageio:

import imageio.v3 as iio
# Read an image
image = iio.imread('image.jpg')
print(image.shape) # output (329, 559, 3)
# Write the image to a new file
iio.imwrite('newimage.jpg', image)
PYTHON

In this example, Imageio reads an image file and prints its shape. It then writes the image to a new file.

Output

imageio python (How it Works for Developers): Figure 1 - Read and Write Image using Imageio

Advanced Features

Imageio provides many advanced features for more complex image-processing tasks:

  1. Reading from Various Sources: Imageio can read images from files, URLs, and even byte streams.
  2. Animated Images: It supports reading and writing animated images like GIFs.
  3. Video Processing: Imageio can handle video files, allowing you to read and write video frames.
  4. Volumetric Data: It supports reading and writing volumetric data, which is useful for scientific applications.

Example: Creating a GIF

Here’s an example of how to create a GIF from a series of images using Imageio:

import imageio.v2 as imageio
import numpy as np  # numpy array
# List of image file paths
image_files = ['img1.jpg', 'img2.jpg'] # images
# Read images and store them in a list
images = []
for file in image_files:
    images.append(imageio.imread(file))
# Save the images as a GIF
imageio.mimsave('output2.gif', images, duration=1000)
PYTHON

In this example, Imageio reads a series of images and creates an animated GIF.

imageio python (How it Works for Developers): Figure 2 - GIF Output

Introducing IronPDF

imageio python (How it Works for Developers): Figure 3 - IronPDF: The Python PDF Library

IronPDF is a powerful Python library designed to create, edit, and sign PDFs using HTML, CSS, images, and JavaScript. It offers commercial-grade performance with a low memory footprint and an easy interface. The key features include:

HTML to PDF Conversion:

Convert HTML files, HTML strings, and URLs to PDFs. For example, render a webpage as a PDF using the Chrome PDF renderer.

Cross-Platform Support:

IronPDF is designed for Python 3+ and also runs on Windows, Mac, Linux, or Cloud Platforms.
IronPDF is also available in .NET, Java, Python, and Node.js.

Editing and Signing:

Set properties, add security with passwords and permissions, and apply digital signatures to your PDFs.

Page Templates and Settings:

You can customize PDFs with headers, footers, page numbers, and adjustable margins. It additionally supports custom paper sizes and responsive layouts.

Standards Compliance:

Complies with PDF standards, including PDF/A and PDF/UA, supports UTF-8 character encoding, and manages assets such as images, CSS, and fonts.

Installation

pip install ironpdf

Generate PDF Documents using IronPDF and Imageio

Prerequisites

  1. Make sure Visual Studio Code is installed as a code editor
  2. Python version 3 is installed

To start with, let us create a Python file to add our scripts.

Open Visual Studio Code and create a file, ImageioDemo.py.

Install necessary libraries:

pip install Imageio
pip install ironpdf

Then add the below code to demonstrate the usage of IronPDF and Imageio python packages.

import imageio.v2 as imageio
import numpy as np
from ironpdf import * 
# Apply your license key
License.LicenseKey = "your key"
# List of image file paths
image_files = ['img1.jpg', 'img2.jpg','img3.jpg']
# Read images and store them in a list
images = []
for file in image_files:
    images.append(imageio.imread(file))
# Save the images as a GIF
imageio.mimsave('output2.gif', images, duration=500)
ImageToPdfConverter.ImageToPdf("output.gif").SaveAs("ironPdf-imageio.pdf")
PYTHON

Code Explanation

This script converts a list of image files (`img1.jpg`, `img2.jpg`, `img3.jpg`) into a GIF and then converts that GIF into a PDF document.

  1. Importing Libraries: imageio.v2 as imageio: Imports the `imageio` library for image processing. numpy as np: Imports NumPy for numerical operations (though not explicitly used in the provided code snippet). from ironpdf import *: Imports necessary functions from the IronPDF library.
  2. License Key: License.LicenseKey = "your key": Sets the license key for IronPDF library. Replace `"your key"` with the actual license key.
  3. Image File List: image_files = ['img1.jpg', 'img2.jpg', 'img3.jpg']: Defines a list containing paths to three image files (`img1.jpg`, `img2.jpg`, `img3.jpg`).
  4. Reading Images: for file in image_files: images.append(imageio.imread(file)): Iterates through each file path in `image_files`, reads the image using `imageio.imread()`, and appends the image data to the `images` list.5. Creating a GIF: imageio.mimsave('output2.gif', images, duration=500): Saves the images stored in the `images` list as a GIF file named `'output2.gif'`. The `duration=500` parameter specifies the duration (in milliseconds) for each frame in the GIF.
  5. Converting GIF to PDF: ImageToPdfConverter.ImageToPdf("output.gif").SaveAs("ironPdf-imageio.pdf"): Converts the GIF file (`"output.gif"`) generated in the previous step to a PDF using IronPDF's `ImageToPdfConverter` and saves it as `"ironPdf-imageio.pdf"`.

The script first reads multiple image files, compiles them into a GIF animation with specified frame durations, and then converts this GIF animation into a PDF document using IronPDF library functionalities. The GIF images are stored as a series of images in the PDF as shown below.

Output

imageio python (How it Works for Developers): Figure 4 - Animated GIF

PDF

imageio python (How it Works for Developers): Figure 5 - PDF Output

IronPDF License

IronPDF runs on the license key for Python. IronPDF for Python offers a free-trial license key to allow users to check out its extensive features before purchase.

Place the License Key at the start of the script before using the IronPDF package:

from ironpdf import * 
# Apply your license key
License.LicenseKey = "key"
PYTHON

Conclusion

Imageio is a powerful and flexible library for image processing in Python. Its ease of use, wide format support, and advanced features make it a valuable tool for developers and data scientists. Whether you need to perform simple image manipulations or handle complex image/volumetric data, Imageio provides the functionality you need in a user-friendly package. IronPDF is a versatile Python library designed for creating, manipulating, and converting PDF documents. It supports tasks such as generating PDFs from scratch, converting HTML and images to PDFs, and performing various document operations like merging and securing PDF files. It's cross-platform compatible and integrates seamlessly with Python applications, making it a powerful tool for handling PDF-related tasks programmatically.

Together with these libraries, we can work with image processing and store the results in PDF format for archiving purposes.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
< PREVIOUS
deepstream io (How it Works for Developers)
NEXT >
igraph python (How it Works for Developers)

Ready to get started? Version: 2025.4 just released

View Licenses >