how can convert image cmyk to rgb mode in javascript

。_饼干妹妹 提交于 2019-12-11 13:27:01

问题


I have a problem:

Browsers do not support showing images in CMYK mode and the client see some really sharp and different colors in his uploaded image while the colors is alright.

solve this problem i think its a good idea to convert an CMYK image to a RGB mode image in client-side with using JavaScript language.

based on my search result about converting image in CMYK to RGB mode with using JavaScript, required image to be imported to a canvas and makes every color number in each pixel convert CMYK to RGB color number with using like this library ColorConverter and finally i have a canvas with RGB mode

this what i am thinking, now my question is if this solution is right ? and if there is any better way to do the job ? please give me your ideas.


回答1:


Browsers do not support showing images in CMYK mode

Showing CMYK images correctly wouldn't be possible as it is relative to the output device, and converting for simulated preview would need a locally calibrated and accurate ICC profile (or at least a high quality approximated profile if accuracy is not required).

You could simply convert each CMYK pixel into RGB, however, since RGB has a wider gamut than CMYK you might end up with a very bright looking result.

In my opinion the better approach is to implement a conversion setup at server side when uploading using ImageMagick or similar software which can take into account ICC profiles. This will allow you to keep the original CMYK file for download/print and a converted and approximated RGB version for preview purposes (you could f.ex. allow client to upload their output ICC for accurate preview).

In any case, the formula to convert CMYK data directly to RGB is:

var C, M, Y, K;   // initialize with normalized values

Then

var r = 255 * (1 - C) * (1 - K);
var g = 255 * (1 - M) * (1 - K);
var b = 255 * (1 - Y) * (1 - K);

The alpha channel is set to fully opaque.



来源:https://stackoverflow.com/questions/37641733/how-can-convert-image-cmyk-to-rgb-mode-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!