Convert from CMYK to RGB

Christopher Perry picture Christopher Perry · Oct 13, 2015 · Viewed 7k times · Source

I'm having trouble converting a single page pdf (CMYK) to a jpg (RGB). When I use the code below, the colors in the jpg image are garish. I've tried reading through the Wand docs, but haven't found anything to simply replicate the original image. The official ImageMagick docs themselves are still rather opaque to me. For my situation, it is necessary to do this within a python script.

Below is the relevant code snippet.

with Image(filename = HOME + outFileName + ".pdf", resolution = 90) as original:
    original.format = "jpeg"
    original.crop(width=500, height=500, gravity="center")
    original.save(filename = HOME + outFileName + ".jpg")

How can I accurately convert from CMYK to RGB?

UPDATE: Here are links to a sample pdf and its converted output.

Original PDF

Converted to JPG

Answer

Temak picture Temak · May 2, 2016

This script will convert image to RGB and save it in-place if it detects that the image is in CMYK mode:

from PIL import Image
image = Image.open(path_to_image)
if image.mode == 'CMYK':
    image = image.convert('RGB')