Page 1 of 1

Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T11:41:59-07:00
by Rye
So, as they say "a picture says more than a thousand words":

I want to go from this:

Image

to this:

Image

However I can't think of a way to rotate and append (while exanding the canvas without further instructing just how much) how exactly this might work.

Any help is appreciated.

-Rye-

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T12:14:11-07:00
by GeeMack
Rye wrote: 2017-03-09T11:41:59-07:00However I can't think of a way to rotate and append (while exanding the canvas without further instructing just how much) how exactly this might work.
Using "-distort SRT" allows for modifying the viewport size, rotating images on a particular center point, and finishing by moving that center point to another particular location all in one operation. Find out more about "-distort SRT" at THIS link.

Applying that "-distort ..." operation, combined with "-set option:distort:viewport" to set the output "window" size, and including some FX expressions to calculate sizes and rotations, you might come up with a command like this which does the whole thing...

Code: Select all

convert quarter.png -duplicate 3 -background none -virtual-pixel none ^
   -set option:distort:viewport "%[fx:w*2]x%[fx:h*2]" ^
   -distort SRT "%[w],0 1 %[fx:t*90] %[w],%[h]" +repage -flatten wholecircle.png
That uses Windows CMD syntax, but translating it to *nix shell should only require changing the carets "^" to backslashes "\".

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T12:57:35-07:00
by fmw42
Here is another way (Unix syntax)

Code: Select all

convert quarter.png -trim +repage -write mpr:img \
\( mpr:img -flip \) +swap -append \
\( -clone 0 -flop \) +append \
result.png
Please always provide your platform/OS, since syntax differs between Unix and Windows.

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T13:06:15-07:00
by GeeMack
Rye wrote: 2017-03-09T11:41:59-07:00However I can't think of a way to rotate and append (while exanding the canvas without further instructing just how much) how exactly this might work.
Another straightforward approach would be to duplicate the image, rotate one of the pair as necessary, and append them horizontally to make a half circle. Then duplicate that, rotate one of that pair so appending them vertically creates the whole circle. It still uses the "-distort SRT" operation I mentioned in my previous comment. That allows for conditionally rotating, scaling, etc., depending on and individual image's position in the stack. This would create the result in your example...

Code: Select all

convert quarter.png ^
   +duplicate -distort SRT "%[fx:t?-90:0]" +append ^
   +duplicate -distort SRT "%[fx:t?0:180]" -append wholecircle.png
Again, that's Windows syntax. Translating it to *nix should be a simple matter of changing carets "^" to backslashes "\".

The cloning, flipping, flopping, and appending method described by fmw42 above may be as simple as it gets.

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T13:59:14-07:00
by Rye
Nice !

Tried this one, out of the various suggestions:

Code: Select all

convert quarter.png ^ +duplicate -distort SRT "%[fx:t?-90:0]" +append ^ +duplicate -distort SRT "%[fx:t?0:180]" -append whole.png
and it works like a charm :)

Only one thing is strange:
When I try and modify it like this (as I'm a windows user.. sorry for not mentioning):

Code: Select all

[b]for %%x in (*png) do [/b]convert %%x ^ +duplicate -distort SRT "%[fx:t?-90:0]" +append ^ +duplicate -distort SRT "%[fx:t?0:180]" -append 0-%%x
the result images are... blank... any ideas on why this is ?
The code should still for, even if looped, right ?

Thanks again for the quick replies - you guys are awesome :D

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T14:18:41-07:00
by fmw42

Code: Select all

Why the [b] and [/b]?

Code: Select all

You have ^ characters that are not at the end of lines. Why?

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T15:26:41-07:00
by GeeMack
Rye wrote: 2017-03-09T13:59:14-07:00When I try and modify it like this (as I'm a windows user.. sorry for not mentioning):

Code: Select all

[b]for %%x in (*png) do [/b]convert %%x ^ +duplicate -distort SRT "%[fx:t?-90:0]" +append ^ +duplicate -distort SRT "%[fx:t?0:180]" -append 0-%%x
the result images are... blank... any ideas on why this is ?
The code should still for, even if looped, right ?
The first thing I notice is you're using double percent "%%" signs on your loop variable like "%%x", and for the FX expressions in the IM command you only have single percent "%" signs like "%[fx:t?-90:0]". If you're running that code in a BAT script they all have to be double percent marks "%%". If you're running it from a command line they should all be singles "%".

Also, the carets "^" in your code line are not needed as long as there aren't line breaks at those locations. They aren't doing anything and they could cause problems with other parts of the code.

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-09T23:02:02-07:00
by Rye
Ah! Right, that variables aswell.

Thanks :) that worked !

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-10T04:51:05-07:00
by snibgo
The flip-flop method seems the most natural one to me, but here is another method that is probably faster. (Not that speed matters for such a small image.) Windows CMD syntax.

Code: Select all

convert quarter.png -virtual-pixel mirror -set option:distort:viewport "%[fx:w*2]x%[fx:h*2]+0+%[fx:h]" -filter point -distort SRT 0 x.png
No image duplication, no rotation or appending, just one operation that visits each of the output pixels once.

Re: Rotate image 4 and append to original to create "complete set"

Posted: 2017-03-10T09:40:19-07:00
by GeeMack
snibgo wrote: 2017-03-10T04:51:05-07:00No image duplication, no rotation or appending, just one operation that visits each of the output pixels once.
I hadn't considered setting the geometry within the viewport setting. Thanks for mentioning that. I tried "-distort affine ..." and came up with a pretty simple method, too. It's similar to your example in that it uses "-virtual-pixel mirror" to get the dupes and mirrors, and gets there by sliding the image to a new location in the viewport.

Code: Select all

convert quarter.png -set option:distort:viewport "%[fx:w*2]x%[fx:h*2]" ^
   -filter point -virtual-pixel mirror -distort affine "0,%[h] 0,0" circle.png