简体   繁体   English

如何在javascript中将图像cmyk转换为RGB模式

[英]how can convert image cmyk to rgb mode in javascript

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. 浏览器不支持以CMYK模式显示图像,并且客户端可以在上传的图像中看到一些非常清晰和不同的颜色,而这些颜色还可以。

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. 解决这个问题,我认为使用JavaScript语言在客户端将CMYK图像转换为RGB模式图像是一个好主意。

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 根据我关于使用JavaScript将CMYK图像转换为RGB模式的搜索结果,需要将图像导入画布,并使用像这样的库ColorConverter使每个像素中的每个颜色数字将CMYK转换为RGB颜色数字,最后我有一个RGB模式的画布

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. 请给我你的想法。

Browsers do not support showing images in CMYK mode 浏览器不支持以CMYK模式显示图像

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). 由于与输出设备有关,因此无法正确显示CMYK图像,并且转换为模拟预览将需要本地校准且准确的ICC配置文件(如果不需要准确性,则至少需要高质量的近似配置文件)。

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. 可以将每个CMYK像素简单地转换为RGB,但是,由于RGB的色域比CMYK的色域宽,您最终可能会获得非常明亮的结果。

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. 在我看来,更好的方法是在使用ImageMagick或类似软件上载时,可以在服务器端实施转换设置,其中可以考虑ICC配置文件。 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). 这将允许您保留原始CMYK文件以进行下载/打印,并保留经过转换和近似的RGB版本以进行预览(例如,可以允许客户端上载其输出ICC进行精确预览)。

In any case, the formula to convert CMYK data directly to RGB is: 无论如何,将CMYK数据直接转换为RGB的公式为:

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. Alpha通道设置为完全不透明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM