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?
Asked
Active
Viewed 6,023 times
2
-
2What background work have you done to answer this question? – Arya McCarthy May 06 '17 at 07:29
-
@aryamccarthy Unfortunately I am new user, so stack-overflow doesn't accept my vote at the moment. – hamid darabian May 07 '17 at 11:19
3 Answers
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
-
-
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