2

Is it possible to create a cmyk image using python like a rgb image? suppose we have an 2d array and each element is a 4-dim vector! How can we convert it to a cmyk image?

3 Answers3

5

Have you looked at the Pillow library for images?

from PIL import Image
im = Image.fromarray(A, mode="CMYK")
im.save("your_file.jpeg")
Arya McCarthy
  • 8,554
  • 4
  • 34
  • 56
0

You may discover any useful information in this doc

http://pillow.readthedocs.io/en/3.0.x/handbook/tutorial.html

and this question

Conversion from CMYK to RGB with Pillow is different from that of Photoshop

Community
  • 1
  • 1
bnrc_
  • 63
  • 2
  • 9
  • thanks, but those link haven't answered this question! – hamid darabian May 06 '17 at 07:53
  • 1. Answer is "Yes" - it is possible - and the docs will provide any necessary information for you to get it done. But to do something to transform your array is your job imho. – bnrc_ May 06 '17 at 07:54
0

I have created a python script named ImageMode.py in my Linux Ubuntu, the code is not optimized but it works well!

python3 ImageMode.py test.jpg
from PIL import Image
import sys

arg = sys.argv
if len(arg)==2:

   [file,ext] = str(arg[1]).split('.')
   image = Image.open(arg[1])

   if image.mode == 'CMYK':
       image = image.convert('RGB')

   elif image.mode == 'RGB':
       image = image.convert('CMYK')

   image.save(file+"_"+image.mode+"."+ext)

else:
   print("Argument missing")

If the image is RGB, then the output will be test_CMYK.jpg

rish_hyun
  • 451
  • 1
  • 7
  • 13