Page 1 of 1
+clone and parens
Posted: 2008-11-25T09:20:47-07:00
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:
Code: Select all
convert -size 100x100 plasma: -swirl 200 \( +clone \) +append x:
Version: ImageMagick 6.4.6 2008-11-23 Q8 OpenMP
http://www.imagemagick.org
Running on a Debian system.
Thank you
Re: +clone and parens
Posted: 2008-11-25T10:07:15-07:00
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
Re: +clone and parens
Posted: 2008-11-25T11:01:07-07:00
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.
Re: +clone and parens
Posted: 2008-11-25T12:06:58-07:00
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.
Re: +clone and parens
Posted: 2008-11-25T13:23:58-07:00
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.
Re: +clone and parens
Posted: 2008-11-25T14:07:30-07:00
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.
Re: +clone and parens
Posted: 2008-11-25T14:58:47-07:00
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.
Re: +clone and parens
Posted: 2008-11-25T15:03:52-07:00
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.
Re: +clone and parens
Posted: 2008-11-25T18:06:21-07:00
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.
Re: +clone and parens
Posted: 2008-11-26T11:17:24-07:00
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.
Re: +clone and parens
Posted: 2008-11-26T13:05:46-07:00
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.
Re: +clone and parens
Posted: 2008-11-26T13:56:59-07:00
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.
Re: +clone and parens
Posted: 2008-11-26T22:34:49-07:00
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.
Re: +clone and parens
Posted: 2009-02-10T06:28:42-07:00
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