convert cmyk eps to tiff & keep transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

convert cmyk eps to tiff & keep transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert cmyk eps to tiff & keep transparency

Post by snibgo »

I'm unsure whether you want the output tiff to be sRGB or CMYK.
snibgo's IM pages: im.snibgo.com
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post by marc.roth »

Should be CMYK
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert cmyk eps to tiff & keep transparency

Post 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?
snibgo's IM pages: im.snibgo.com
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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.
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert cmyk eps to tiff & keep transparency

Post 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
snibgo's IM pages: im.snibgo.com
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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.
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert cmyk eps to tiff & keep transparency

Post 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.
snibgo's IM pages: im.snibgo.com
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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
marc.roth
Posts: 10
Joined: 2019-04-23T23:48:28-07:00
Authentication code: 1152

Re: convert cmyk eps to tiff & keep transparency

Post 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"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert cmyk eps to tiff & keep transparency

Post by fmw42 »

+antialias does nothing. It is for writing text into an image and it turns antialiasing off (not on)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert cmyk eps to tiff & keep transparency

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply