How to batch composite / round corners?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

How to batch composite / round corners?

Post by imagefox87 »

Hello,

I have a folder of *.png images that are 717x1045. These are card images with pointed corners. I have a border.png that is also 717x1045 with rounded corners. The border width is 27 pixels. I want to put the border.png on top of the *.png images while maintaining transparency. The corners are rounded because of transparency. Also since the original card image does not have transparency, do I need to drop before composite? If I crop it, then I have to overlay the new cropped image (690x1018) on top of the border.png (717x1045).

I was thinking this could be done from the command line:

composite -gravity center border.png *.png

I'm new to ImageMagick and would just like some guidance as how to do this.

Thanks

Edit: This is a addendum to viewtopic.php?f=1&t=30321
Last edited by imagefox87 on 2016-08-27T13:13:14-07:00, edited 3 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to batch composite?

Post by snibgo »

It's much easier with example images. You can put them on dropbox.com or similar, and paste the URLs here.

I never use "composite" for anything. "convert" is easier.
snibgo's IM pages: im.snibgo.com
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

Sure I will use imgur.

Here is a sample card image with pointed corners: http://i.imgur.com/mg6XH4Z.png
Here is the border with rounded corners and transparency: http://i.imgur.com/FZnvesM.png

I simply want to put the border.png on top of the card image. They are the same size. Since the first image has no transparency, I might have to crop and then overlay. I have thousands of card images like this that need to be processed.
Last edited by imagefox87 on 2016-08-26T14:24:07-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to batch composite?

Post by snibgo »

The images are different sizes:

Code: Select all

f:\web\im>%IM%convert FZnvesM.png Cdw8qii.png info:
FZnvesM.png[0] PNG 813x1185 813x1185+0+0 8-bit sRGB 137KB 0.063u 0:00.062
Cdw8qii.png[1] PNG 717x1045 717x1045+0+0 8-bit sRGB 137KB 0.031u 0:00.031
So I'm not sure what you want. Perhaps:

Code: Select all

convert FZnvesM.png Cdw8qii.png -gravity Center -composite x.png
What do you mean by "drop"?
snibgo's IM pages: im.snibgo.com
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

Oh oops, I can just resize the first one from 813x1185 to 717x1045. I edited post and re-uploaded the border.png in 717x1045. How would I type this in the command line for a batch of these card images? The result should have the same filename. Also I meant "crop" not "drop". That was a typo sorry lol.

convert border.png *.png -gravity center -composite *.png

Is the above correct?
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

I have batch cropped all my images to remove the border. Now I need to add the new border with rounded corners. The card images are now 690x1018 and the border.png is 717x1045. I'm overlaying a batch of 690x1018 over a single image 717x1045 where the resulting image should have the same name as the card images that were 690x1018.

I have a directory card c:\pics with 1000 images *.png with 690x1018 and c:\pics\border\border.png that is 717x1045. I need to overlay them. I've tried composite and it isn't working. I think I have the wrong syntax.
Last edited by imagefox87 on 2016-08-26T15:20:50-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to batch composite?

Post by snibgo »

imagefox87 wrote:How would I type this in the command line for a batch of these card images? The result should have the same filename.
Same filename but different directory, right? I would do it in a shell loop.

If all the images will fit into memory at the same time, you could read them in, with NULL: and then the overlay, "-layers" composite, and mess with the filenames. This should be much faster than a shell loop, but trickier to write.

I wouldn't use "composite".
snibgo's IM pages: im.snibgo.com
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

The thing is I have no idea how to write that. I didn't know overlaying a batch of images over an image can be so complicated lol.
Last edited by imagefox87 on 2016-08-26T15:47:06-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to batch composite?

Post by snibgo »

It isn't complicated. If you use bash or Windows Bat, the "for" command will do it.
snibgo's IM pages: im.snibgo.com
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

How's this:

FOR %G IN (*.png) DO composite -gravity center border\border.png batch\%G
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to batch composite?

Post by snibgo »

Nearly. You need two input files. The other is %G.
snibgo's IM pages: im.snibgo.com
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

One is the %G which is the *.png of card pics and the other is the border.png. What am I missing?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to batch composite?

Post by snibgo »

imagefox87 wrote:composite -gravity center border\border.png batch\%G
This mentions two files. You need three: two inputs and one output.
snibgo's IM pages: im.snibgo.com
imagefox87
Posts: 20
Joined: 2016-08-26T13:37:18-07:00
Authentication code: 1151

Re: How to batch composite?

Post by imagefox87 »

Thanks I figured it out!

for %g in (*.png) do composite -gravity center %g border\border.png batch\%g
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to batch composite?

Post by GeeMack »

snibgo wrote:If all the images will fit into memory at the same time, you could read them in, with NULL: and then the overlay, "-layers" composite, and mess with the filenames. This should be much faster than a shell loop, but trickier to write.
Even IM6 lets you set an output file name formed from the name of each input file. A command to do imagefox87's project of adding frames to the images would look something like this...

Code: Select all

convert c:\pics\*.png -set filename:f "%[t]" null: ^
   c:\pics\border\border.png -gravity center -layers composite "%[filename:f].png"
Post Reply