3

Is there any way to convert an RGB image into a CMYK one using ICC in a python ImageMagick binding. I know you can easily do it in the command-line, but is there anyway to do it in a binding like Wand (preferably Wand)? What I have now is:

from wand.image import Image
from urllib.request import urlopen
response = urlopen('https://www.website.com/path/to/image.jpg')
try:
    with Image(file=response) as img:
        img.type = 'truecolor'
        img.alpha_channel = True
        img = img.colorspace = 'cmyk'
        img.save(filename='converted.jpg')
finally:
    response.close()

This results in the image having HORRIBLY inaccurate colors, but in the correct color space. Is there any way to convert it using a profile? Thanks.

fmw42
  • 46,825
  • 10
  • 62
  • 80
pepper5319
  • 667
  • 4
  • 8
  • 24
  • I am not an expert on Wand, but I do not see anything about profiles in the Wand documentation at https://media.readthedocs.org/pdf/wand/latest/wand.pdf. But I suppose you could make a subprocess call to Imagemagick convert directly in Python. See for example: https://stackoverflow.com/questions/40281613/call-imagemagicks-convert-command-in-python-script. However, the convert command may need one or two profiles depending whether the input image has a CMYK profile or not. – fmw42 Oct 09 '17 at 04:44
  • I know little about Python, but turning on Alpha for a JPG (which doesn't support transparency) seems wrong. Also `img = img.colorspace = 'cmyk'` looks contorted. Maybe you are using alpha as black? – Mark Setchell Oct 09 '17 at 06:31
  • You could also use a subprocess call using EXIFTOOL to add a profile. See, for example, https://stackoverflow.com/questions/6740441/how-to-set-a-color-profile-with-exiftool – fmw42 Oct 10 '17 at 01:34

1 Answers1

1

Try using wand.image.Image.transform_colorspace

with Image(file=response) as img:
    img.transform_colorspace('cmyk')
    img.save(filename='converted.jpg')
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • This essentially gives off the exact same result as `img.colorspace = 'cmyk'`. It doesn't convert using an ICC profile, which is something I am looking for. – pepper5319 Oct 10 '17 at 00:28