How to get the ICC profile of an image using Pillow?

Dec 25, 2025

Leave a message

Sophia Moore
Sophia Moore
Sophia is a marketing manager at Yangzhou Xinkai Textile Hotel Supplies Factory. She uses various marketing strategies to promote the company's products, expanding the company's influence in the market.

Hey there! As a pillow supplier, I've got a lot of experience not just with pillows but also with some cool tech - related stuff, especially when it comes to working with images of our amazing products. Today, I'm gonna share with you how to get the ICC profile of an image using Pillow, a super - handy Python library.

First off, let's talk a bit about what an ICC profile is. ICC stands for International Color Consortium, and an ICC profile is like a set of instructions that tells your computer or a device how to display or print the colors in an image correctly. It's crucial for making sure that the colors you see on your screen match the colors that come out when you print the image or view it on another device.

Now, why would you want to get the ICC profile of an image, especially if you're in the pillow business like me? Well, when we're taking pictures of our Natural Latex Sleeping Pillow, Organic Health Buckwheat Pillow, or High - star Hotel Pillows, we want to make sure that the colors in the images are as accurate as possible. This helps our customers get a better idea of what they're buying.

So, let's dive into how to get the ICC profile using Pillow. First, you need to have Pillow installed. If you haven't already, you can install it using pip. Just open up your terminal and type:

pip install pillow

Once you've got Pillow installed, you're ready to start working with images. Here's a simple Python script that shows you how to get the ICC profile of an image:

from PIL import Image

def get_icc_profile(image_path):
    try:
        img = Image.open(image_path)
        icc_profile = img.info.get('icc_profile')
        return icc_profile
    except Exception as e:
        print(f"An error occurred: {e}")
        return None

# Replace 'your_image.jpg' with the actual path to your image
image_path = 'your_image.jpg'
icc_profile = get_icc_profile(image_path)

if icc_profile:
    print("The ICC profile of the image is:")
    print(icc_profile)
else:
    print("No ICC profile found in the image.")

Let's break down what's going on in this code. First, we import the Image module from the PIL (Python Imaging Library, which is what Pillow is based on). Then we define a function called get_icc_profile that takes the path to an image as an argument. Inside the function, we try to open the image using Image.open(). Once the image is open, we use the info attribute of the image object. This info attribute is a dictionary that contains various metadata about the image, including the ICC profile if it exists. We use the get() method to try and retrieve the icc_profile key from the dictionary. If the key exists, it returns the ICC profile; if not, it returns None.

We also have a try - except block to catch any errors that might occur when opening the image. If an error occurs, we print an error message and return None.

After defining the function, we specify the path to our image and call the get_icc_profile function. If the function returns an ICC profile, we print it; otherwise, we print a message saying that no ICC profile was found.

But what if you want to do something more with the ICC profile? Maybe you want to save it to a file. Here's how you can do that:

from PIL import Image

def get_icc_profile(image_path):
    try:
        img = Image.open(image_path)
        icc_profile = img.info.get('icc_profile')
        return icc_profile
    except Exception as e:
        print(f"An error occurred: {e}")
        return None

image_path = 'your_image.jpg'
icc_profile = get_icc_profile(image_path)

if icc_profile:
    with open('icc_profile.icc', 'wb') as f:
        f.write(icc_profile)
    print("The ICC profile has been saved to icc_profile.icc")
else:
    print("No ICC profile found in the image.")

In this updated code, if we find an ICC profile, we open a new file called icc_profile.icc in binary write mode ('wb') and write the ICC profile data to it.

Natural Latex Sleeping Pillow manufacturersOrganic Health Buckwheat Pillow manufacturers

As a pillow supplier, this kind of image - related tech can be really useful. When we're marketing our pillows, high - quality and accurate images are key. By ensuring that our images have the correct ICC profiles, we can make sure that the colors are consistent across different devices and platforms. This gives our customers a better shopping experience and makes it more likely that they'll be satisfied with their purchase.

If you're in the business of selling pillows or any other products and you're interested in getting high - quality images with accurate colors, we'd love to talk to you. Whether you're looking for our Natural Latex Sleeping Pillow, Organic Health Buckwheat Pillow, or High - star Hotel Pillows, we can work together to make sure your product images look their best. Just reach out to us for a procurement discussion, and we can explore how we can meet your needs.

References:

  • Pillow official documentation
  • Python official documentation
Send Inquiry
Contact usif have any question
You can either contact us via phone, email or online form below. Our specialist will contact you back shortly.
contact us