Sure thing, here's the script:
Input: there are >200 images, each 96 pixels wide and 96 pixel high. They come in different colors; different colors represent different nationalities. In the game I design a board for there are, let me count... say, six nationalities.
Below is a sample counter:
It's the German 61st Infantry Division.
Each counter is resized and slightly sharpened:
Code: Select all
convert zeton.png -resize 66x66 zeton_66x66.png
convert zeton_66x66.png -sharpen 0x0.4 zeton_ostry.png
It results with:
zeton_ostry.png is the input file for further modifications.
Since counters come in different shades, first I have to determine what color needs to be used for borders. The method I use is
very lousy but Windows batch script would just refuse to work with
set color='convert zeton_ostry.png -format "%%[pixel:s.p{5,5}]" info:'. Instead, the color is written to the file from which I subsequently read its RGB value. Well, whatever, but it works! In case of uniformly colored images, this step is not mandatory. In fact, it's better to omit it.
Step A
Code: Select all
convert zeton_ostry.png -format "%%[pixel:s.p{5,5}]" info: >> color.txt
Then I generate an round corner mask which will be used to clip off the counter corners. This example originates from IM documentation:
Step B
Code: Select all
convert zeton_ostry.png -border 5 -alpha transparent -background none -fill white -stroke none -strokewidth 0 -draw "roundrectangle 2,2 73,73 10,10" rounded_corner_mask.png
Step C
Then, using color that was determined in step A, I generate a rounded border. Mind the 'threshold' which is used to eliminate semitransparent pixels.
Code: Select all
FOR /F "delims=" %%B in ('TYPE color.txt') Do (
convert zeton_ostry.png -border 5 -alpha transparent -background none -fill none -stroke %%B -strokewidth 5 -draw "roundrectangle 2,2 73,73 10,10" -channel matte -threshold 20% rounded_corner_overlay.png
)
(it looks much worse when viewed on this forum; it looks best displayed against a black backround)
Step D
The gradient is generated with following code:
Code: Select all
convert -size 76x35 xc:"#aaaaaa" xc:"#444444" -size 76x6 gradient:"#aaaaaa"-"#444444" +swap -append -rotate 270 -distort SRT 45 overlap_mask.png
Gradient spanning through the whole picture width would be to soft. Through experiments I found out a 6-pixel wide gradient works best with the 10-pixel radii I use for rounded corners.
Color values #aaaaaa and #444444 have also been picked up through tinkering with different shades of grey. Pure white and black didn't work too well in this case,
Step E
Gradient is used to lighten/darken the border that was generated in step C:
Code: Select all
convert rounded_corner_overlay.png overlap_mask.png -compose hardlight -composite compose_hardlight.png
Step F
The border is cut from the image generated in step E:
Code: Select all
composite -compose DstIn rounded_corner_overlay.png compose_hardlight.png -alpha Set rounded_corner_overlay_dark.png
Step G
And finally this border is pasted over the counter itself:
Code: Select all
convert zeton_ostry.png -matte -bordercolor none -border 5 rounded_corner_mask.png -compose DstIn -composite rounded_corner_overlay_dark.png -compose Over -composite zeton_ostry_frame.png
yielding final image
I do know it all can be squeezed into fewer lines but, first of all, it's the third day I've been using IM, secondly, I am happy it works, if I start to tweak it, I will surely break it.