Automation of Cropping

Wargame counters in games usually come in sheets, with each sheet containing several dozens of counters. To create a module–among other things–one needs to cut these into individual counters. This can be–and in fact is–tedious, boring and time consuming to the point of discouraging potential module developers from creating modules at all.

This article addresses, at least to some extent, this issue, providing you with tools and knowledge required to let you cut the counter sheets in 5% time you would spend otherwise.

Consider counter sheet from Ardennes ’44 (following images are used only as samples; in real life situation you would use original images, not scans, for module implementation; for educational purposes these are more than enough, though):

Front:

Back:

Open these in your favorite graphic editor and cut top left stripe from the front sheet and corresponding stripe from the back sheet (which will be top right stripe, mind you):

Front (front-stripe.jpg)

Back: (back-stripe.jpg)

As there are 9 counters in one row, width of stripe in pixel should be divisible by 9 (549px in my case) to ensure all the counters have same width. Counters of non-uniform width is nothing ImageMagick can't handle, of course, but for purpose of this tutorial let's assume we want them to be equal.

With your favorite text editor create a Windows batch file containing following commands:

magick front-tripe.png -crop 9x2@ output\front-^%%02d.png
magick back-stripe.png -flop -crop 9x2@ -flop output\back-^%%02d.png

Run it to cut stripes into individual counters:

Note: ^%% is a Windows idiom that within BAT resolves to %. % has a special meaning in Windows batch programming. In Linux environments these commands would be a bit different.

Notice–and this is of crucial importance–that both front and back of the same counter have a common suffix:

Now, note that with back looking as above, as ImageMagick crops image from left to right, we would have suffixes mixed up if we didn't account for that. That is why we need -flop command that "mirrors" the stripe vertically:

Another -flop flips the (now individual) image back.

Explanation

Let’s dissect command magick front-stripe.png -crop 9x2@ output\front-^%%02d.png to better understand what is happening:

  1. front-stripe.png is the input file
  2. -crop 9x2@ orders ImageMagick to crop stripe into 18 individual files, 9 columns each in row, 2 rows.
  3. output\front-^%%02d.png orders ImageMagick to save cropped files in folder named output. %02d adds two digit suffix to each file (left-padded with 0 if required)

Automated cropping and VASSAL Mass Piece Loader

VASSAL Mass Piece Loader allows to define a suffix of counter backs; you may want to change commands to:

magick front-stripe.png -crop 9x2@ output\counter-^%%02d.png
magick back-stripe.png -flop -crop 9x2@ -flop output\counter-^%%02d-back.png

and instruct Vassal to interpret files with -back suffix as backs of counters sharing the remainder of the filename:

.

Also: http://www.vassalengine.org/forum/viewtopic.php?f=6&t=10770