[英]ImageMagick inconsistent behaviour between Mac/Linux build. CMYK files corrupted on Linux
I am bulk converting PDF's to TIFF images.我正在将 PDF 批量转换为 TIFF 图像。
bash scripts are written on and tested on a Mac, then pushed to a Ubuntu box for production runs. bash 脚本在 Mac 上编写和测试,然后推送到 Ubuntu 盒子进行生产运行。 (it has better spec)
(它有更好的规格)
Strangely, some pages (1 in 100 or so) exported images are corrupted.奇怪的是,某些页面(大约 100 个页面中的 1 个)导出的图像已损坏。 after multiple runs, image corruption happens on the same pages, suggesting this is not a random runtime error.
多次运行后,同一页面上发生图像损坏,这表明这不是随机运行时错误。
Pages are exported from Adobe InDesign CC2020 using the same PDF/X4 profile.使用相同的 PDF/X4 配置文件从 Adobe InDesign CC2020 导出页面。 All follows similar composition of text with styles, placed over monochrome images.
所有都遵循与 styles 类似的文本组合,放置在单色图像上。
Left: Correct / Right: Corrupted左:正确/右:损坏
Just for completeness, I tried im6 (ubuntu20.4 default) convert command, but resulted with the same result.为了完整起见,我尝试了 im6 (ubuntu20.4 默认) convert 命令,但结果相同。
This is the options I run my batch (via GNU Parallel).这是我运行批处理的选项(通过 GNU Parallel)。 Is there something wrong I may be doing, in my script?
在我的脚本中,我可能做错了什么吗?
convert \
-verbose \
-alpha off \
-colorspace Gray \
-contrast-stretch 0 \
-depth 8 \
-compress zip \
-units PixelsPerInch \
-density 1200 \
${1} \
${1%.*}.tiff
From searching I found that there may be issues between im6 and im7 and how they handle colour profiles, but they are version matched as below:通过搜索我发现im6和im7之间以及它们如何处理颜色配置文件之间可能存在问题,但它们的版本匹配如下:
versions as shown by magick --version
:如
magick --version
所示的版本:
Mac (homebrew):
Version: ImageMagick 7.0.11-14 Q16 x86_64 2021-05-31 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(5.0)
Delegates (built-in): bzlib fontconfig freetype gslib heic jng jp2 jpeg lcms lqr ltdl lzma openexr png ps tiff webp xml zlib
Ubuntu20.04 (v7 installed with https://github.com/SoftCreatR/imei/ )
Version: ImageMagick 7.0.11-14 Q32 x86_64 2021-05-17 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg jxl lcms lqr ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zip zlib
And here are identify command result from PDF files:以下是 PDF 文件中的识别命令结果:
identify result: PDF file with export problems识别结果:PDF 文件存在导出问题
Image:
Filename: 05.pdf
Format: PDF (Portable Document Format)
Mime type: application/pdf
Class: DirectClass
Geometry: 380x533+0+0
Resolution: 72x72
Print size: 5.27778x7.40278
Units: Undefined
Colorspace: CMYK
Type: ColorSeparation
Endianness: Undefined
Depth: 16/8-bit
Channel depth:
Cyan: 1-bit
Magenta: 1-bit
Yellow: 1-bit
Black: 8-bit
identify result: PDF file without problems:识别结果:PDF文件没有问题:
Image:
Filename: 06.pdf
Format: PDF (Portable Document Format)
Mime type: application/pdf
Class: DirectClass
Geometry: 380x533+0+0
Resolution: 72x72
Print size: 5.27778x7.40278
Units: Undefined
Colorspace: sRGB
Type: PaletteAlpha
Base type: Undefined
Endianness: Undefined
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
I noticed that I seem to have problems with files in CMYK colourspace and not sRGB.我注意到我似乎对 CMYK 色彩空间中的文件而不是 sRGB 有问题。
However, that to me does not explain why it works on a Mac, but not on Ubuntu.但是,对我来说,这并不能解释为什么它可以在 Mac 上工作,但不能在 Ubuntu 上工作。
Perhaps Ubuntu build, contain CMYK library different to Mac build?也许 Ubuntu 构建,包含不同于 Mac 构建的 CMYK 库? Is there a way to confirm my suspicion?
有没有办法证实我的怀疑?
I may have arrived at a work around.我可能已经解决了。
the issue seemed to arise from this part:问题似乎来自这部分:
Channel depth:
Cyan: 1-bit
Magenta: 1-bit
Yellow: 1-bit
Black: 8-bit
Original image is for print in monochrome.原始图像用于单色打印。 Such that all channels of CMY except K contains no data, stored as bit depth of 1.
这样 CMY 的除 K 外的所有通道都不包含数据,存储为位深度为 1。
Still not yet clear why it works on a Mac, but here's a version that works on Linux build too:仍然不清楚为什么它可以在 Mac 上运行,但这里有一个版本也适用于 Linux 版本:
convert \
-verbose \
-alpha off \
-colorspace CMYK \
-contrast-stretch 0 \
-depth 8 \
-channel black -negate -separate \
-compress zip \
-units PixelsPerInch \
-density 1200 \
${1} \
${1%.*}.tiff
The key was to render in CMYK first, as original PDFs are intended for.关键是首先以 CMYK 进行渲染,因为原始 PDF 是用于此目的的。
Then strip CMY channels, to create a pure Grayscale image.然后剥离 CMY 通道,创建纯灰度图像。 (note K channels need to be negated)
(注意K通道需要取反)
Snippet above works consistently for both Mac/Linux.上面的代码片段对 Mac/Linux 都有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.