Page 1 of 2

convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T00:19:30-07:00
by marc.roth
Hi there,

I'm almost finished reading all posts about this issue and I've also tried dozens of tipps to convert my images precisely to a transparent tiff. :?

Code: Select all

- transparent #000  >  drops the required white areas
- floodfill +0+0  >  corrupts the image
- colorspace RGB & and RGBA  >  distorts the colors
- fuzz & fill none  >  doesn't work (for some reason  :shock: )
- ...
Is there somebody out there who had the same issues and solved them finally? You can take the challenge looking at the following eps and desired tif (created manually). One more hint - the background and areas with cmyk(0,0,0,1) should be transparent, white areas with cmyk(0,0,0,0) should be kept.

https://1drv.ms/f/s!Ap9W5wxhL4jWhNYFaKezBcM1_KxzQA

Good luck :D

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T05:30:02-07:00
by snibgo
I'm unsure whether you want the output tiff to be sRGB or CMYK.

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T05:32:19-07:00
by marc.roth
Should be CMYK

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T05:51:38-07:00
by marc.roth
Maybe one more important note.
Our endpoint only only allows us to use "one-liner convert commands". So it might be not possible to reuse images etc.

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T06:02:20-07:00
by snibgo
What version of IM, on what platform? I'll assume IM v7.

Your inputs have only one image. If they had more, we might use "[0]" suffix.

The basic conversions are simply:

Code: Select all

magick -density 300 test01.eps out1.tiff

magick -density 300 test02.eps out2.tiff
"-density" is not required, but the results are very small if I omit that.
marc.roth wrote:the background and areas with cmyk(0,0,0,1) should be transparent
What range are those numbers? Out of 1, or 255, or what? If out of 1, then cmyk(0,0,0,1) is black. Do you want to make black transparent?

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T06:08:22-07:00
by marc.roth
We're using ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28 on a Ubuntu 18.04 LTS.
There can always be only one image submitted to the convert function through the frontend.
Those values are from 0 to 100 with substractive color mixing. Therefore CMYK(0,0,0,1) is near to white and should be transparent as well as the transparent background from the eps. Black and all other colours shouldn't be transparent.

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T06:18:49-07:00
by marc.roth
Here's one of my tries having already using density.

convert -quiet -density 1200 -colorspace CMYK -channel RGBA -alpha on +antialias eps:"test01.eps" -background 'cmyk(0,0,0,0)' -fill transparent -opaque 'cmyk(0,0,0,1)' -antialias -resize 1700x1700 -repage 0x0 -density 300 -depth 8 -compress lzw -strip TIFF:"test01.tif"

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T06:57:30-07:00
by snibgo
IM delegates the rasterisation of EPS to Ghostscript. GS can't return CMYKA images. So if we want to retain the CMYK transparency, we need to tell GS to make an RGBA image, then convert that back to CMYKA. "+antialias" can be used, as you do, to tell GS not to antialias.

Code: Select all

convert -verbose -density 1200 -colorspace sRGB test01.eps -colorspace CMYK t.tiff
We can output the unique colours:

Code: Select all

convert -density 1200 -colorspace sRGB +antialias test02.eps -colorspace CMYK -unique-colors txt:

# ImageMagick pixel enumeration: 8,1,65535,cmyka
0,0: (0,0,0,0,65535)  #0000000000000000FFFF  cmyka(0,0,0,0,1)
1,0: (0,0,0,771,65535)  #0000000000000303FFFF  cmyka(0,0,0,3,1)
2,0: (0,7490,5617,56540,65535)  #00001D4215F1DCDCFFFF  cmyka(0%,11%,9%,86%,1)
3,0: (44887,43989,0,28013,65535)  #AF57ABD500006D6DFFFF  cmyka(68%,67%,0%,43%,1)
4,0: (0,5483,54308,1028,65535)  #0000156BD4240404FFFF  cmyka(0%,8%,83%,2%,1)
5,0: (0,17128,62928,20303,65535)  #000042E8F5D04F4FFFFF  cmyka(0%,26%,96%,31%,1)
6,0: (0,34192,61057,24158,65535)  #00008590EE815E5EFFFF  cmyka(0%,52%,93%,37%,1)
7,0: (0,0,0,0,0)  #00000000000000000000  cmyka(0,0,0,0,0)
We have transparent white, cmyka(0,0,0,0,0). cmyka(0,0,0,3,1) is out of 255, so this is your cmyk(0,0,0,1) out of 100. We can make all colours that are within 1.5% of white into tranparent:

Code: Select all

convert -density 1200 -colorspace sRGB +antialias test02.eps -colorspace CMYK -fuzz 1.5% -transparent cmyk(0,0,0,3) t.tiff

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T07:26:40-07:00
by marc.roth
You're right, the only way would be to use the RGB colorspace. The problem is thtat the colours are mixed up converting it back to a CMYK image. Even if I use the right color profiles I'm not able to get the correct color back.

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T07:38:32-07:00
by marc.roth
... what gave me a clue about using a mask (see below). Now the only issue is to get this one running as an one-liner-command as decribed before.
Is it possible to concat those separate commands into one and use some sort of temporary file instead of a physical one (here mask02.png)?

convert -quiet -density 1200 -depth 8 -colorspace SRGB +antialias "test02.eps" -colorspace CMYK -transparent cmyk(0,0,0,3) -antialias -resize 1700x1700 -repage 0x0 -density 300 -strip -alpha Extract -negate "mask02.png"
convert -quiet -density 1200 -colorspace CMYK +antialias "test02.eps" -antialias -resize 1700x1700 -repage 0x0 -density 300 -strip -depth 8 -compress lzw TIFF:"test02.tif"
convert "test02.tif" -alpha Activate "mask02.png" -compose CopyAlpha -composite -depth 8 -compress lzw TIFF:"test02_final.tif"

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-24T08:06:23-07:00
by snibgo
Yes, we can rasterise twice: first to get the RGBA transparency, second to get the CMYK colours. Then "copyOpacity". I would save the mask as "mpr:", so we can use that in the same command (Windows BAT syntax):

Code: Select all

convert ^
  -density 300 ^
  -background None ^
  -colorspace sRGB ^
  test02.eps ^
  -alpha Extract ^
  +write mpr:MASK ^
  +delete ^
  -density 300 ^
  test02a.eps ^
  mpr:MASK ^
  -alpha off ^
  -compose CopyOpacity -composite ^
  out.tiff
You can do whatever processing you want between reading test02.eps and reading mpr:MASK, and after the composite.

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-25T03:18:13-07:00
by marc.roth
I'm on the right track, but there's still an issue taking the colorspace cmyk into the second conversion.
Running the command without works like a charm.

Code: Select all

convert -quiet -density 300 -background None -colorspace sRGB "test02.eps" -alpha Extract +write mpr:MASK +delete -density 300 -colorspace CMYK test02.eps mpr:MASK -alpha off -compose CopyOpacity -composite out.tif

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-30T05:52:45-07:00
by marc.roth
This one finally solved all issues (tested with IM 6.9 on Ubuntu 18.04)

Code: Select all

convert -quiet -density 1200 -depth 8 -colorspace SRGB +antialias eps:"test02.eps" -colorspace CMYK -transparent 'cmyk(0,0,0,3)' -antialias -resize 1700x1700 -repage 0x0 -density 300 -strip -alpha Extract -negate +write mpr:MASK +delete -density 1200 -colorspace CMYK +antialias eps:"test.eps" -antialias -resize 1700x1700 -repage 0x0 -density 300 +write mpr:TEMP +delete mpr:TEMP -alpha Activate mpr:MASK -compose CopyOpacity -composite -depth 8 -compress lzw  TIFF:"test02.tif"
As always Windows works different (tested with IM 7.0 on Windows 10)

Code: Select all

convert -quiet -density 1200 -depth 8 -colorspace SRGB +antialias eps:"test02.eps" -colorspace CMYK -transparent cmyk(0,0,0,3) -antialias -resize 1700x1700 -repage 0x0 -density 300 -strip -alpha Extract +write mpr:MASK +delete -density 1200 -colorspace CMYK +antialias eps:"test.eps" -antialias -resize 1700x1700 -repage 0x0 -density 300 +write mpr:TEMP +delete mpr:TEMP -alpha Activate mpr:MASK -compose CopyOpacity -composite -depth 8 -compress lzw  TIFF:"test02.tif"

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-30T09:25:14-07:00
by fmw42
+antialias does nothing. It is for writing text into an image and it turns antialiasing off (not on)

Re: convert cmyk eps to tiff & keep transparency

Posted: 2019-04-30T09:40:18-07:00
by snibgo
fmw42 wrote:+antialias does nothing.
"+antialias" does do something here: it tells Ghostscript not to antialias the graphic image, so the edges are jagged.