[RESOLVED]possible bug using clip-paths and anti-aliasing in IM 7

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

[RESOLVED]possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

There are two issues here.

1) The change in default density to 96 and how that is used in Inkscape 0.92 causes the rendered images from imagemagick, which sets the default to 90, to be too small and gives an error message when doing the clipping.

2) My alternate and perhaps better method works fine in IM 6, but fails in IM 7.

Here are the details:

For those using Inkscape to render SVG files, please note that inkscape version 0.92 has recently been modified so as to work properly with a default density 96. For versions prior to 0.92, the default was 90. But when use ImageMagick to call inkscape, ImageMagick sends a density of 90 to be consistent with older versions of Inkscape. Using ImageMagick with Inkscape 0.92, if no density is defined in the SVG file will render at density 90 and the result will be too small. This can bee seen for example if one does

Code: Select all

identify svg.svg
svg.svg SVG 1076x1076 1076x1076+0+0 8-bit sRGB 40309B 0.000u 0:00.000

which is wrong whereas using the MSVG (or RSVG renderer).

Code: Select all

identify MSVG:svg.svg
MSVG:svg.svg=>svg.svg MSVG 1148x1148 1148x1148+0+0 16-bit sRGB 3811B 0.000u 0:00.000


The real issue comes when one tries to extract the clip path and use it to clip an image with Inkscape 0.92. For example from https://imagemagick.org/Usage/masking/#clip-path

Code: Select all

convert -quiet 852067A.tif[0] -alpha transparent -clip -alpha opaque -strip out.tiff
convert: image size differs `852067A.tif' @ error/image.c/SetImageClipMask/2655.


A better method is as follows (using IM 6.9.10.14)

Code: Select all

identify -quiet -format "%[8BIM:1999,2998:#1]" 852067A.tif[0]  |\
convert -quiet 852067A.tif[0] +repage \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -density 96 - -negate -blur 0x1 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
out.tif
Note that in the above I set the density to 96 for use with my inkscape 0.92. I also include some anti-aliasing using -blur and convert the CMYK tiff file to sRGB using profiles.

Unfortunately, the above code does not work with the anti-aliasing for me on my Mac OSX Sierra with IM 7 and produces a totally transparent result. But if I remove the -blur 0x1 -level 50x100% it does work properly.

Here is the file if anyone else wants to check this out to see if the IM 7 issue is just on my Mac.

http://www.fmwconcepts.com/misc_tests/c ... 52067A.tif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by snibgo »

For v7, try "-channel RGB" before the blur and "+channel" after the level.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

snibgo wrote: 2018-11-30T19:51:05-07:00 For v7, try "-channel RGB" before the blur and "+channel" after the level.
I had tried that before and just tried it again. But it does not help. In this case, I believe that it won't matter, since the clip path (SVG or 8BIM) was opaque.

I have posted the tiff image that I was using, if anyone wants to check on other platforms. I was using Mac OSX Sierra.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

I tested the following code in IM 7.0.8.15 Q16 HDRI Mac OSX Sierra and still got the same fully transparent image. I also tested in IM 7.0.8.16 Beta and now get an error message.

Code: Select all

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 852067A.tif[0]  |\
magick -quiet 852067A.tif[0] +repage \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -density 96 - -negate -blur 0x1 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
out.tif
magick: no images found for operation `+repage' at CLI arg 3 @ error/operation.c/CLIOption/5263.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

The above command is giving a totally transparent result in IM 7.0.8.20 Q16
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by magick »

We cannot download http://www.fmwconcepts.com/misc_tests/c ... 52067A.tif. We get a permissions exception.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

Try now.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: pos852067A.sible bug using clip-paths and anti-aliasing in IM 7

Post by magick »

Add

Code: Select all

-background none
right after

Code: Select all

-density 96
.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

That does not work for me using IM 7.0.10.20 Q16. It just leaves an outline in green around a transparent figure.

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 852067A.tif[0] |\
magick -quiet 852067A.tif[0] +repage \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -density 96 -background none - -negate -blur 0x1 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
852067A_clip.tif

http://www.fmwconcepts.com/misc_tests/c ... A_clip.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

Note if I remove the -negate, then I get the expected result where the green figure is not transparent. I just want to reverse this so the everything but the green is transparent.

Here is the command without the negate.

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 852067A.tif[0] |\
magick -quiet 852067A.tif[0] +repage \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -density 96 - -blur 0x1 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
852067A_no_negate.tif

http://www.fmwconcepts.com/misc_tests/c ... negate.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug using clip-paths and anti-aliasing in IM 7

Post by fmw42 »

I figured it out. I have to add -channel rgb (or -alpha off) with IM 7 before the -negate.

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 852067A.tif[0] |\
magick -quiet 852067A.tif[0] +repage \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -density 96 - -channel rgb -negate -blur 0x1 -level 50x100% +channel \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
852067A_clip2.tif

http://www.fmwconcepts.com/misc_tests/c ... _clip2.tif
Post Reply