How to batch composite / round corners?
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
Also do you guys know how to use -chop in order to cut just 12x12 from all 4 corners?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to batch composite?
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.
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
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.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: How to batch composite?
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 ^
) ^
Make sure the directory named "output" already exists. To run this from a Windows BAT script you'd have to change all the single percent signs "%" to doubles "%%".
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
@GeeMack: Thank you so much man! You're a life saver. Glad to know that people provide code here for free.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: How to batch composite?
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.
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to batch composite?
My mistake above about using -crop. It should have been -composite. Here is my approach (unix syntax) for one image. You make a white background the size of the image and composite as 12x12 black image at each corner, then put the result into the alpha channel of the image.
Input:
Other shapes could be created using -draw to replace the simple black square.
And add a shadow:
Ref: http://www.fmwconcepts.com/imagemagick/ ... und_shadow
Input:
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
Other shapes could be created using -draw to replace the simple black square.
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
And add a shadow:
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
Ref: http://www.fmwconcepts.com/imagemagick/ ... und_shadow
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
@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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to batch composite?
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?
See my addition of a shadow in the post above that has been edited to include that.
P.S. It is just a variation on what GeeMack did. There are lots of ways to do things in IM.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to batch composite?
For windows users, for a single image, this would be my rounded corners command. (Windows users, please correct me if this is wrong).
Remove \ from ( and from ) and change line ending \ to ^. For bat syntax double % to %%
Note the output directory must exist already
You probably need to follow Geemack's approach to be able to handle wild card inputs for multiply input and output files.
But you could write a loop over all your images and process them one at a time in the loop with the above command.
Remove \ from ( and from ) and change line ending \ to ^. For bat syntax double % to %%
Note the output directory must exist already
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"
But you could write a loop over all your images and process them one at a time in the loop with the above command.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to batch composite?
If all your input images are the same size, then you can do wild cards with my command as follows (similar to what GeeMack does using null: and layers composite). see http://www.imagemagick.org/Usage/anim_mods/#composite
Windows format:
Windows format:
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"
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
All of your codes work but the processing time is very large and it uses the RAM. Hence, I want to use a for loop that saves an image as soon as that image is processed rather than storing it in RAM. I'm using this code to process up to 12,000 images. Other programs like XnConvert usually take 3-4 hours to do this but it it saves the images as they are being done so you know how long and it doesn't slow the computer
I've been reading this: http://www.imagemagick.org/Usage/windows/#for_loops
I'm not sure if I need "^" based on the syntax. This is GeeMack's original code with some modifications. Here is my code:
Any help would be appreciated.
I've been reading this: http://www.imagemagick.org/Usage/windows/#for_loops
I'm not sure if I need "^" based on the syntax. This is GeeMack's original code with some modifications. Here is my code:
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"
)
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to batch composite?
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.
-
- Posts: 20
- Joined: 2016-08-26T13:37:18-07:00
- Authentication code: 1151
Re: How to batch composite?
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"
)