Python Convert EPS to PNG with Pillow: A Beginner Guide – Python Tutorial

By | August 30, 2020

We can convert a png image to eps with python pillow. Here is an example:

Python Pillow Convert PNG to EPS: A Completed Guide

How to convert an eps image to png with pillow? In this tutorial, we will tell you how to do.

Prepare an eps image

from PIL import Image

image_eps = 'logo-CMYK.eps'
im = Image.open(image_eps)

In code above, we use pillow to open an eps image called ‘logo-CMYK.eps‘. Then, we will convert it to png.

Convert CMYK color mode to RGBA

The color mode of ‘logo-CMYK.eps‘ is CMYK, we will convert it to RGBA, which is a color mode used in png image.

fig = im.convert('RGBA')

Convert eps to png

After having converted color mode, we can convert eps to png.

image_png= 'logo-rgb.png'
fig.save(image_png, lossless = True)

Run this python script, we will find the eps file is converted to png.

Here is the effect.

python pillow convert eps to png

If you find OSError: Unable to locate Ghostscript on paths when converting, you can read this tutorial to fix it.

Fix OSError: Unable to locate Ghostscript on paths for Python Beginners