Re: How to batch composite?
Posted: 2016-08-26T17:41:22-07:00
Also do you guys know how to use -chop in order to cut just 12x12 from all 4 corners?
Use https://github.com/ImageMagick/ImageMagick/discussions instead.
https://imagemagick.com/discourse-server/
https://imagemagick.com/discourse-server/viewtopic.php?t=30365
How about -region geometry? Because the northeast,southeast, northwest, and southwest are not specific enough for gravity.fmw42 wrote:As far as I know, -chop will only chop full rows or columns. You will have to use -crop with -gravity 4 times to get all 4 corners.
We came up with one like this last week to answer a different question. I modified it a bit to chop a 12x12 square from every corner of every PNG in the directory and save them all to another directory with their original flienames...imagefox87 wrote:Also do you guys know how to use -chop in order to cut just 12x12 from all 4 corners?
Code: Select all
convert *.png ^
-set filename:f "%[t]" ^
-background none ^
-gravity northwest ^
( ^
-size 12x12 ^
xc:black ^
-write mpr:corner ^
-delete 0--1 ^
) ^
( ^
-clone 0--1 ^
-fill white ^
-colorize 100% ^
null: ^
mpr:corner -layers composite -rotate 90 ^
null: ^
mpr:corner -layers composite -rotate 90 ^
null: ^
mpr:corner -layers composite -rotate 90 ^
null: ^
mpr:corner -layers composite -rotate 90 ^
-write mpr:masks ^
-delete 0--1 ^
) ^
null: ^
mpr:masks ^
-compose copyopacity ^
-layers composite ^
"output/%[filename:f].png"
Code: Select all
( ^
-size 12x12 ^
xc:black ^
-write mpr:corner ^
-delete 0--1 ^
) ^
Code: Select all
( ^
-size 12x12 ^
xc:black ^
-draw "fill white circle 12,12 12,0" ^
-write mpr:corner ^
-delete 0--1 ^
) ^
If you ever show up in the area of Peoria, Illinois, you're buying dinner.imagefox87 wrote:@GeeMack: Thank you so much man! You're a life saver. Glad to know that people provide code here for free.
Sure, np man haha. I was going to say a beer, but dinner is cool with me too. Btw, if you ever play the card game, Yu-Gi-Oh, let me know. I can give you a free version of a MSE master template that is currently the best highest quality template available on the net.GeeMack wrote: If you ever show up in the area of Peoria, Illinois, you're buying dinner.
Code: Select all
convert lena.jpg \
\( -size 12x12 xc:black -write mpr:corner +delete \) \
\( -clone 0 -fill white -colorize 100% \
mpr:corner -gravity northwest -compose over -composite \
mpr:corner -gravity northeast -compose over -composite \
mpr:corner -gravity southeast -compose over -composite \
mpr:corner -gravity southwest -compose over -composite \) \
-alpha off -compose copy_opacity -composite lena_corners12.png
Code: Select all
convert lena.jpg \
\( -size 25x25 xc:black -fill white \
-draw "circle 25,25 25,0" -alpha off \
-write mpr:corner +delete \) \
\( -clone 0 -fill white -colorize 100% \
\( mpr:corner \) -gravity northwest -compose over -composite \
\( mpr:corner -rotate 90 \) -gravity northeast -compose over -composite \
\( mpr:corner -rotate 180 \) -gravity southeast -compose over -composite \
\( mpr:corner -rotate 270 \) -gravity southwest -compose over -composite \) \
-alpha off -compose copy_opacity -composite lena_corners25c.png
Code: Select all
convert lena.jpg \
\( -size 25x25 xc:black -fill white \
-draw "circle 25,25 25,0" -alpha off \
-write mpr:corner +delete \) \
\( -clone 0 -fill white -colorize 100% \
\( mpr:corner \) -gravity northwest -compose over -composite \
\( mpr:corner -rotate 90 \) -gravity northeast -compose over -composite \
\( mpr:corner -rotate 180 \) -gravity southeast -compose over -composite \
\( mpr:corner -rotate 270 \) -gravity southwest -compose over -composite \) \
-alpha off -compose copy_opacity -composite -compose over \
\( +clone -background black -shadow 80x3+5+5 \) \
+swap -background none -layers merge +repage lena_corners25cs.png
Yes, but you generally want to draw a circle and the radius of the circle should match the square black background size. So you want to draw the center of the circle in the bottom right corner for the orientation I used.imagefox87 wrote:@fmw42: This is also a great method thank you! I'm assuming that the radius of the circle you draw controls the curvature of the rounded corners?
Code: Select all
convert path2inputdir/lena.jpg ^
-set filename:f "%[t]" ^
( -size 25x25 xc:black -fill white ^
-draw "circle 25,25 25,0" -alpha off ^
-write mpr:corner +delete ) ^
( -clone 0 -fill white -colorize 100% ^
( mpr:corner ) -gravity northwest -compose over -composite ^
( mpr:corner -rotate 90 ) -gravity northeast -compose over -composite ^
( mpr:corner -rotate 180 ) -gravity southeast -compose over -composite ^
( mpr:corner -rotate 270 ) -gravity southwest -compose over -composite ) ^
-alpha off -compose copy_opacity -composite -compose over ^
( +clone -background black -shadow 80x3+5+5 ) ^
+swap -background none -layers merge +repage "path2outputdir/%[filename:f].png"
Code: Select all
convert path2inputdir/* -set filename:f "%[t]" ^
null: ^
( -size 25x25 xc:black -fill white ^
-draw "circle 25,25 25,0" -alpha off ^
-write mpr:corner +delete ) ^
( -clone 0 -fill white -colorize 100% ^
( mpr:corner ) -gravity northwest -compose over -composite ^
( mpr:corner -rotate 90 ) -gravity northeast -compose over -composite ^
( mpr:corner -rotate 180 ) -gravity southeast -compose over -composite ^
( mpr:corner -rotate 270 ) -gravity southwest -compose over -composite ) ^
-alpha off -compose copy_opacity -layers composite "path2outputdir/%[filename:f].png"
Code: Select all
@ECHO OFF
for %%g in (*.png) do (
convert %%g ^
-background none ^
-gravity northwest ^
( ^
-size 12x12 ^
xc:black ^
-draw "fill white circle 12,12 12,0" ^
-write mpr:corner ^
-delete 0--1 ^
) ^
( ^
-clone 0--1 ^
-fill white ^
-colorize 100%% ^
null: ^
mpr:corner -layers composite -rotate 90 ^
null: ^
mpr:corner -layers composite -rotate 90 ^
null: ^
mpr:corner -layers composite -rotate 90 ^
null: ^
mpr:corner -layers composite -rotate 90 ^
-write mpr:masks ^
-delete 0--1 ^
) ^
null: ^
mpr:masks ^
-compose copyopacity ^
-layers composite ^
"batch/%%g"
)
I've converted yours too but it doesn't start:fmw42 wrote:His code above that you reference loads all the images in memory. You should take my single image solution above (at viewtopic.php?f=1&t=30365&start=15#p137074) and put a for loop around it. Sorry, I do not code Windows bat scripts, so cannot be of much help.
Code: Select all
@ECHO OFF
for %%g in (*.png) do (
convert %%g
( -size 25x25 xc:black -fill white ^
-draw "circle 25,25 25,0" -alpha off ^
-write mpr:corner +delete ) ^
( -clone 0 -fill white -colorize 100%% ^
( mpr:corner ) -gravity northwest -compose over -composite ^
( mpr:corner -rotate 90 ) -gravity northeast -compose over -composite ^
( mpr:corner -rotate 180 ) -gravity southeast -compose over -composite ^
( mpr:corner -rotate 270 ) -gravity southwest -compose over -composite ) ^
-alpha off -compose copy_opacity -composite -compose over ^
( +clone -background black -shadow 80x3+5+5 ) ^
+swap -background none -layers merge +repage "batch/%%g"
)