Page 1 of 1

Issue with applying clipping paths

Posted: 2011-09-22T08:33:00-07:00
by sven
First of all, I used the following two versions of ImageMagick to verify the problem described below.

Versions
  • ImageMagick 6.7.2-6 2011-09-16 Q16
  • ImageMagick 6.5.4-7 2010-12-13 Q16 OpenMP
Moreover, here are the results of calling convert -list format for each of the two versions: These are the two commands used that lead to the issue described below:

Code: Select all

convert src_test_l.jpg +clip-path '#1' -fill transparent -draw "matte 0,0 reset" result_left.png
convert src_test_r.jpg +clip-path '#1' -fill transparent -draw "matte 0,0 reset" result_right.png
These are the corresponding source files and resulting files:
http://www.filedropper.com/files_9

Description of the problem:
Image

1. The outer path (red square) of the image src_test_l.jpg was created clockwise. The inner path around the blue square L was created clockwise as well. The inner path around the blue square R was created counter-clockwise.
Result of the command mentioned above: The inner path around the blue square R is applied properly, the path around the blue square L is not.

2. The outer path (red square) of the image src_test_r.jpg was created counter-clockwise. The inner path around the blue square R was created counter-clockwise as well. The inner path around the blue square L was created clockwise.
Result of the command mentioned above: The inner path around the blue square L is applied properly, the path around the blue square R is not.

Assumption: The inner paths are applied properly only if they were created opposed to the outer path.

Re: Issue with applying clipping paths

Posted: 2011-09-22T21:37:19-07:00
by anthony
The draw path direction is dependant on another draw option. fill-rule
see the examples involving fill-rule in
http://www.imagemagick.org/Usage/draw/#paths

Typically holes are created in paths by actually going in the opposite direction to the outside path. This makes the direction count within the hole zero which is correct for either fill-rule. That is the correct way of making holes in a path.

It is only if the inside loop is in the same direction as the outside loop that the fill-rule will define whether it should be classed as a hole or simple an extra path drawn on top of the existing path. More typically it defines how paths that cross over and loop back on themselves should be handled.

Re: Issue with applying clipping paths

Posted: 2011-09-23T02:50:13-07:00
by Matthias
Hello Anthony,
how can i apply a different fill-rule to the "+clip-path '#1'" command? The only Examples that I've found are within the -draw "fill-rule nonzero path ...'" option.
I've also tried to apply the fill-rule in the -draw "matte" command:

Code: Select all

convert src_test_l.jpg +clip-path '#1' -fill transparent -draw "fill-rule nonzero matte 0,0 reset" result_left.png
But this didn't make any difference.
Thanks for your help
Matthias

Re: Issue with applying clipping paths

Posted: 2011-09-24T03:00:37-07:00
by anthony
No the fill rule will not be applied to clipping paths. Not unless you draw the clipping pather to generate your own clipping mask. The path being used should be listed in a verbose identify of the input image.

But if the clipping path is designed correctly, then holes have a zero cycle count and then the fill rule does not matter! This is a major lesson that is taught in university graphic courses, and yes I not only took that subject I later tutored that subject three years later when I returned to do honours.

It does not matter what direction the cycle is, as long and holes are in the opposite direction. The other way to look at it is that when drawing any polygon (outside edge, holes, or even objects inside holes) is to always draw so that the filled part (actual shape) is on either the left or the right side of the direction the line is being drawn.

NOTE; that when you get to 3 dimensional polygonal meshes the direction of the fill also becomes important as the cycle direction determines the the polygons 'normal vector' as defined by a cross product vector, typically using the right hand rule. The normal vector is typically used to determine if a point is inside the object, or in simple object whether the polygon is facing away from the camera viewpoint and then a 'back face' and can be ignored for backface removal. But that is getting a little beyond the current topic.

In summery if the clipping path is defined properly holes in the clipping path are no problem.

Re: Issue with applying clipping paths

Posted: 2011-09-26T08:01:58-07:00
by sven
Anthony,

Thanks a lot for your explanations.

Unfortunately, it does not seem to be current practice to actually consider the direction of paths when drawing. At least, for Adobe Photoshop it does not seem to matter at all. You can draw a path starting anywhere and tell whether this path is to be subtracted or not.

Nevertheless, can you think of any approach of how to always get a hole in the examples mentioned above?

Thanks a lot in advance.

Kind regards,
Sven