Rotate image 4 and append to original to create "complete set"
Rotate image 4 and append to original to create "complete set"
So, as they say "a picture says more than a thousand words":
I want to go from this:
to this:
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-
I want to go from this:
to this:
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-
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Rotate image 4 and append to original to create "complete set"
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Rotate image 4 and append to original to create "complete set"
Here is another way (Unix syntax)
Please always provide your platform/OS, since syntax differs between Unix and Windows.
Code: Select all
convert quarter.png -trim +repage -write mpr:img \
\( mpr:img -flip \) +swap -append \
\( -clone 0 -flop \) +append \
result.png
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Rotate image 4 and append to original to create "complete set"
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
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"
Nice !
Tried this one, out of the various suggestions:
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):
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
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
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 code should still for, even if looped, right ?
Thanks again for the quick replies - you guys are awesome
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Rotate image 4 and append to original to create "complete set"
Code: Select all
Why the [b] and [/b]?
Code: Select all
You have ^ characters that are not at the end of lines. Why?
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Rotate image 4 and append to original to create "complete set"
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 "%".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):the result images are... blank... any ideas on why this is ?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 code should still for, even if looped, right ?
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"
Ah! Right, that variables aswell.
Thanks that worked !
Thanks that worked !
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Rotate image 4 and append to original to create "complete set"
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.
No image duplication, no rotation or appending, just one operation that visits each of the output pixels once.
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
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Rotate image 4 and append to original to create "complete set"
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