+clone and parens

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

+clone and parens

Post by RetroJ »

Hello,
I found that the +clone operator does not behave as I would expect when not enclosed in parens. I would expect the result of the first command given below to be similar to that of the second, where the right-hand clone is also swirled. I was surprised because this behavior seems to break with convert's semantics of "everything is processed left to right".

Code: Select all

convert -size 100x100 plasma: -swirl 200 +clone +append x:
Image

Code: Select all

convert -size 100x100 plasma: -swirl 200 \( +clone \) +append x:
Image

Version: ImageMagick 6.4.6 2008-11-23 Q8 OpenMP http://www.imagemagick.org
Running on a Debian system.

Thank you
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: +clone and parens

Post by el_supremo »

Anthony's examples explains that clone is only intended to be used within parentheses so it probably doesn't work as expected when there aren't any around it.
see: http://www.imagemagick.org/Usage/basics/#clone

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: +clone and parens

Post by RetroJ »

This is a use-case for +clone in which I do not need to do further processing on the clone, hence there is no logical call for the grouping construct.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: +clone and parens

Post by fmw42 »

RetroJ wrote:This is a use-case for +clone in which I do not need to do further processing on the clone, hence there is no logical call for the grouping construct.
It makes more logical sense to group your first commands and then clone, so the clone sees the result of the command not the input plasma image

convert \( -size 100x100 plasma: -swirl 200 \) +clone +append x:

So this should work fine.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: +clone and parens

Post by RetroJ »

fmw42 wrote:It makes more logical sense to group your first commands and then clone, so the clone sees the result of the command not the input plasma image

convert \( -size 100x100 plasma: -swirl 200 \) +clone +append x:

So this should work fine.
Since operators have left-associativity in convert, no grouping should be necessary at all in this example.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: +clone and parens

Post by fmw42 »

RetroJ wrote:
fmw42 wrote:It makes more logical sense to group your first commands and then clone, so the clone sees the result of the command not the input plasma image

convert \( -size 100x100 plasma: -swirl 200 \) +clone +append x:

So this should work fine.
Since operators have left-associativity in convert, no grouping should be necessary at all in this example.

This is what Anthony's clone notes say:

Note that "-clone" without the use of parenthesis will just copy images from the current image sequence and directly append them. However this is not its intended use and is to be discouraged as it will produce a different result if you later surround that set of operations by parenthesis.

The first image in the sequence is the plasma: without the parenthesis.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: +clone and parens

Post by RetroJ »

fmw42 wrote:This is what Anthony's clone notes say:

Note that "-clone" without the use of parenthesis will just copy images from the current image sequence and directly append them. However this is not its intended use and is to be discouraged as it will produce a different result if you later surround that set of operations by parenthesis.

The first image in the sequence is the plasma: without the parenthesis.
As he summarizes, the behavior of -clone without parentheses is completely un-useful, and because it is un-useful, and produces inconsistent results, it is discouraged. That is why my request is that the behavior of -clone without parentheses be changed to do something useful. The intuitive and useful thing to do in this case would be to clone the image after having applied the operators appearing to the left of -clone, in normal left-to-right order.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: +clone and parens

Post by fmw42 »

I don't find it quite so un-useful. The last example I sent, makes quite a bit of sense to me. But Anthony will have to judge and explain further.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: +clone and parens

Post by anthony »

RetroJ wrote:This is a use-case for +clone in which I do not need to do further processing on the clone, hence there is no logical call for the grouping construct.
Even though +clone works without parenthesis, do not use it that way. If you later add parenthesis around your set of operations to use it as a sub-set of a more complex set, you will get in to trouble.

It is was never ment to be used without parenthesis! It was created to pull in images into a sub-sequence of operations - on the side.

An alternative to +clone is -write mpr:{label} then read the iameg using mpr:{label} however this does the WHOLE image sequnece, and not specific images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: +clone and parens

Post by RetroJ »

anthony wrote:Even though +clone works without parenthesis, do not use it that way. If you later add parenthesis around your set of operations to use it as a sub-set of a more complex set, you will get in to trouble.

It is was never ment to be used without parenthesis! It was created to pull in images into a sub-sequence of operations - on the side.

An alternative to +clone is -write mpr:{label} then read the iameg using mpr:{label} however this does the WHOLE image sequnece, and not specific images.
Please consider my post about this issue as a feature request to change the behavior of -clone when used without parentheses. This would constitute an improvement to the user-interface of convert, because -clone would now be "meant to be used" in any context at all, and the problem of unpredictable results "if you later add parentheses" would be eliminated. The use-case in my initial post shows the obvious desired effect that anyone would expect of -clone, who did not have such esoteric knowledge as that they had to either use "extra" parentheses or an mpr: for such a trivial operation as appending a manipulated image to itself.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: +clone and parens

Post by magick »

We have a fix for the problem you reported. Look for it in the next point release of ImageMagick within a few days. Thanks.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: +clone and parens

Post by RetroJ »

magick wrote:We have a fix for the problem you reported. Look for it in the next point release of ImageMagick within a few days. Thanks.
Many thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: +clone and parens

Post by anthony »

[quote="RetroJPlease consider my post about this issue as a feature request to change the behavior of -clone when used without parentheses. This would constitute an improvement to the user-interface of convert, because -clone would now be "meant to be used" in any context at all, and the problem of unpredictable results "if you later add parentheses" would be eliminated. The use-case in my initial post shows the obvious desired effect that anyone would expect of -clone, who did not have such esoteric knowledge as that they had to either use "extra" parentheses or an mpr: for such a trivial operation as appending a manipulated image to itself.[/quote]

Actually I agree with you and that is what is should do. But that isn't its original design and even though it is fix, it should it is not recommended usage. adding parenthesis around it is not a great strain, but makes it correct usage. In all IM examples that is what I do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rockcreekdan
Posts: 6
Joined: 2008-05-15T04:06:34-07:00

Re: +clone and parens

Post by rockcreekdan »

Sorry to resurrect this thread, but I was using IM to arrange pictures on a 5x7 page for printing and encountered this behavior of -clone. Two things:

1) Could the command line options web page please be modified to include the recommendation to use parentheses with -clone? I figured out the correct usage by trial and error.

2) Typically I use the built-in version of IM supplied with Ubuntu, which is 6.3.7. Recently, I grabbed the "Portable" distribution for windows, and started to run it under wine, so that I can try out new features.

The following command actually segfaults under wine (IM 6.4.8-8 Q16 OpenMP) and Windows XP (IM 6.4.9-2 Q16 OpenMP), but does not when parentheses are placed around +clone. No segfault from Ubuntu's IM 6.3.7, though.

wine convert -size 600x900 xc:black -bordercolor white -border 75x75 +clone -append +clone +append test.jpg
Post Reply