Pillow can convert other format images to eps image. However, we often encounter ValueError: image mode is not supported error. In this tutorial, we will introduce how to fix this error for beginners.
Why this error occur?
Because when we use pillow to convert other types of images to eps. Pillow only can read L, LAB, RGB and CMYK mode image. If the mode of image is not, image mode error will occur.
How to fix this error?
Here is an example to convert png to eps.
from PIL import Image image_png = 'logo.png' image_eps = 'logo.eps' im = Image.open(image_png) im.save(image_eps, lossless = True)
Run this python script, we will find this error: ValueError: image mode is not supported.
Check the image mode of current image
Here we can find the mode is RGBA, which is not a mode pillow can read and convert to eps.
How to change image mode to pillow can convert to eps?
We can use image.convert() function to change mode of image.
Here is an example:
fig = im.convert('RGB')
In this tutorial, we will convert RGBA mode to RGB mode.
Then we will convert this image to eps.
fig.save(image_eps, lossless = True)