从CMYK转换为RGB [英] Convert from CMYK to RGB
问题描述
我在将单页pdf(CMYK)转换为jpg(RGB)时遇到麻烦.当我使用下面的代码时,jpg图像中的颜色是扎眼的.我曾尝试阅读Wand文档,但没有发现任何可以简单复制原始图像的东西.官方的ImageMagick文档本身对我来说还是不透明的.对于我来说,有必要在python脚本中执行此操作.
I'm having trouble converting a single page pdf (CMYK) to a jpg (RGB). When I use the code below, the colors in the jpg image are garish. I've tried reading through the Wand docs, but haven't found anything to simply replicate the original image. The official ImageMagick docs themselves are still rather opaque to me. For my situation, it is necessary to do this within a python script.
下面是相关的代码段.
with Image(filename = HOME + outFileName + ".pdf", resolution = 90) as original:
original.format = "jpeg"
original.crop(width=500, height=500, gravity="center")
original.save(filename = HOME + outFileName + ".jpg")
如何准确地将CMYK转换为RGB?
How can I accurately convert from CMYK to RGB?
更新:以下是指向示例pdf及其转换后的输出的链接.
UPDATE: Here are links to a sample pdf and its converted output.
推荐答案
如果该脚本检测到图像处于CMYK
模式,则该脚本会将图像转换为RGB
并保存在原位:
This script will convert image to RGB
and save it in-place if it detects that the image is in CMYK
mode:
from PIL import Image
image = Image.open(path_to_image)
if image.mode == 'CMYK':
image = image.convert('RGB')
这篇关于从CMYK转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!