EPS with clipping path convert to png with transparent background

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?".
Post Reply
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-06T22:47:10-07:00

hi,
I am new to imagesmagick and try to convert EPS with clipping path to png. The png should only have image with transparent background. I searched forum and found some similar topics using script:
convert -colorspace "sRGB" input.eps -alpha "transparent" -clip -alpha "opaque" output.png
When i apply this script, the -clip removes image rather than background. So the output.png becomes a white with nothing on it.
I also tried
convert input.eps +clip-path "#1" -alpha "transparent" output.eps
I get the same result. Can anyone help me? I am using IM-7.0.5-Q16 and Ghostscript 9.21.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: EPS with clipping path convert to png with transparent background

Post by fmw42 » 2017-08-06T23:28:55-07:00

In IM 7 you need to use magick in place of convert. See viewtopic.php?f=3&t=31924&p=146061&hilit=clip#p146049. The bug was fixed in IM 7.0.5.6. So depending upon your 7.0.5.x version, you may need to upgrade Imagemagick.

For novices, see

viewtopic.php?f=1&t=9620http://http://w ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/

janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-08T14:49:09-07:00

Thank you. I have upgraded to IM 7.0.6 and clip works on eps file. But the converted png file has very jagged edge. Is any way i can make it better?

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: EPS with clipping path convert to png with transparent background

Post by fmw42 » 2017-08-08T16:43:38-07:00

Can you upload your EPS file to some place such as dropbox.com and put the URL here so we can test with it. If not, then try

Code: Select all

convert -density 288 input.eps +clip-path "#1" -alpha "transparent" -resize 25% output.eps
or just leave the -resize 25% out.

janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-08T22:50:44-07:00

I tried your script and get the same jagged edge. My current script is:
magick -density 300 -depth "8" -colorspace "sRGB" input.eps -alpha "transparent" -clip -alpha "opaque" -resize "400x400" output.png
I also try to add -fuzz 1% -fill none but no luck.
I don't have dropbox account. My eps file is about 40MB. Any other way i can send eps through?

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: EPS with clipping path convert to png with transparent background

Post by fmw42 » 2017-08-08T23:37:24-07:00

Only way is if you have our own server and can upload there. Dropbox is free, so that is a good solution.

This works for me? Does it work for you?

http://www.fmwconcepts.com/misc_tests/c ... OV_EPS.eps

Code: Select all

convert -density 150 -colorspace sRGB 218755504_HOV_EPS.eps -alpha transparent -clip -alpha opaque -strip 218755504_HOV_EPS_im6.png
If that works, try

Code: Select all

convert -density 600 -colorspace sRGB 218755504_HOV_EPS.eps -alpha transparent -clip -alpha opaque -strip -resize 25% 218755504_HOV_EPS_im6_2.png
Why are you using +clip-path "#1"?

The + sign turns off that clip path. See http://www.imagemagick.org/Usage/masking/#clip-path

janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-09T21:26:23-07:00

The script
convert -density 600 -colorspace sRGB 218755504_HOV_EPS.eps -alpha transparent -clip -alpha opaque -strip -resize 25% 218755504_HOV_EPS_im6_2.png
has better output than the first one. But the right edge of png image is better than the left and top edge. I also tried couple of my own eps images and got the same result. very interesting. Not sure how i fix the left and top edge issue.
What's the delegate libpng version included in the Windows IM 7.0.6-Q16? If i remove -strip, i get the error message:
"convert: profile 'icc': 'CMYK': invalid ICC profile color space @ warning/png.c/MagickPNGWarningHandler/1744."
If i use -strip, i can only get 72dpi png not 300dpi which i want.

janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-09T22:11:44-07:00


User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: EPS with clipping path convert to png with transparent background

Post by fmw42 » 2017-08-09T22:44:50-07:00

This works for me on IM 6.9.9.5 Q16 and IM 7.0.6.5 Q16 HDRI Mac OSX and produces a transparent background PNG. If it works for you and you want an EPS output, then change the output suffix to .eps. (for IM 7 change convert to magick)

Code: Select all

convert -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip test1_output.png
Image

janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-10T22:45:52-07:00

Thank you for the script. I know where is the jagged issue from. It's from -resize
If i do your script:
convert -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip test1_output.png
I get the good anti-aliased result, but if i want to resize png to certain size, i do:
convert -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip -resize 1000x1000 test1_output.png
I get the jagged edge. Looks like -resize causing the issue.
If i use pipe to get the output png,
"magick -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip PNG:- | magick - -resize 1000x1000 test1_output.png"
The jagged issue is gone.
Any other way i can fix this jagged issue without using pipe command? Since IM4Java needs bit more code to work out pipe thing.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: EPS with clipping path convert to png with transparent background

Post by fmw42 » 2017-08-11T09:42:45-07:00

I do not see any aliasing with this command with the addition of -resize 1000x1000 using IM 6.9.9.5 Q16. But I do with IM 7.0.6.5 Q16 HDRI. That looks like a bug or an HDRI issue.

IM 6

Code: Select all

convert -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip -resize 1000x1000 test1_output2a.png
Image


IM 7

Code: Select all

magick -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip -resize 1000x1000 test1_output2b.png
Image


If you still have trouble, then you can antialias by blurring the edges of the alpha channel. Try

Code: Select all

magick -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip -resize 1000x1000 -alpha on -channel a -blur 0x3 -level 50x100% +channel test1_output3.png
Image


Increase or decrease the 3 on -blur 0x3 as desired for more or less anti-aliasing.

However, you do point out that it does not occur if you pipe before resizing.

Code: Select all

magick -density 300 -units pixelsperinch -colorspace srgb test1.eps -alpha transparent -clip -alpha opaque -strip PNG32:- | magick - -resize 1000x1000 test1_output2c.png
Image


janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: EPS with clipping path convert to png with transparent background

Post by janebrandhub » 2017-08-13T16:41:02-07:00

Thank you all. This issue is resolved.

Post Reply