Counter image manipulations
The script piece_manip.sh
(Right-click and select Save link as …) allows for a number of manipulations of counter images. The syntax is in general
./piece_manip.sh [OPTIONS] INPUT ...
where OPTIONS
specify which operations to do, and INPUT ...
is a number of input files. Try also
./piece_manip.sh --long-help
for information on operations. If no output file is specified via option -o
or --output
, then for input file INPUT.EXT
, the default output file name is INPUT_out.png
.
The script uses ImageMagick, and is inspired by grouchysmurf’s, now defunct, web-page vassal.neocities.org
(Wayback machine). Credit to that user for finding various useful operations.
This script is not meant to be omnipotent. Many more possible and sensible operations could be defined, and much more fancy stuff can be done with ImageMagick. Please refer to the document of ImageMagick, not least the extensive list of examples.
Overview
Original | --bevel |
--border |
--color |
--crop |
--drop |
--expand |
--outline |
--rounded |
--shade |
--shave |
Combined |
---|---|---|---|---|---|---|---|---|---|---|---|
Some common notes
Colours
Any colour that Imagemagicks knows about can be used, or alternatively the colour can be given using HTML colour codes (#RRGGBB
, where RR
, GG
, BB
, are hexadecimal numbers between 0x00
and 0xFF
, and corresponds to the red, green, and blue channels, respectively).
Sizes
Sizes are always given in image pixels.
Copyright
Typically, the publisher of the game holds the copyright on the materials of the game. While copyright can most likely not be claimed over game mechanics and design, it can be enforced on artistic and original work. Graphics, such as counters, maps, cards, etc. definitely fall in that category.
Thus, if you modify or redistribute such materials - counters, maps, cards, etc. - you should make sure that the copyright holders have given you license to do so, and you should explicitly provide that license. Otherwise, you are most likely liable for copyright infringement.
Crop images from counter sheet
./piece_manip.sh --extract N M [FLIP] INPUT ...
where INPUT
is N
columns and M
rows of pieces. If FLIP
is true
, yes
, 1
, flip
, flop
, or back
, then the order of pieces are reversed. This is useful when extracting images from the “back” counter sheet so as to reproduce the order of the images used on the front sheet.
Output file names are
INPUT_NUM.png
where NUM
is a serial number, starting at zero, zero-padded to 3 digits - e.g., if the input file name is front_block.png
, then the 6th extracted image will be named front_block_005.png
.
Examples
./piece_manip.sh --extract 9 2 front_block.png
./piece_manip.sh --extract 9 2 1 back_block.png
Input:
Given the counter sheets
cut out the individual blocks, using for example Gimp, as shown below
Output:
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Bevel
./piece_manip.sh --bevel [SIZE] INPUT ...
Add a bevel (“button” effect) of size SIZE pixel to images. If SIZE
is not specified it defaults to 4
Example
./piece_manip.sh --bevel 4 counter1.png -o counter1_bevel.png
./piece_manip.sh --bevel 4 counter2.png -o counter2_bevel.png
Border
./piece_manip.sh --border [SIZE [COLOUR]] INPUT ...
Add a COLOUR
-coloured border of size SIZE pixel to images. If SIZE
is not specified it defaults to 4
. If COLOUR
is not specified, it defaults to black
.
Example
./piece_manip.sh --border 1 red counter1.png -o counter1_border.png
./piece_manip.sh --border 1 red counter2.png -o counter2_border.png
Color
./piece_manip.sh --color [N [DITHER]] INPUT ...
Reduce the number of colours used by the image to N
(defaults to 16). If DITHER
is no
, false
, no-dither
, 0
, or off
, then dithering is turned off (default is on). The purpose of this operation is to reduce the image size. For many images, the size can be reduced to about 25% of the original size.
Example
./piece_manip.sh --color 5 5 -o counter1_color.png
./piece_manip.sh --color 5 5 -o counter2_color.png
Crop
./piece_manip.sh --crop GEOM INPUT ...
Crop piece to geometry GEOM
. GEOM
has the format
WIDTHxHEIGHT[+/-X+/-Y]
where WIDTH
and HEIGHT
are the new width and height, respectively, and X
and Y
are the horizontal and vertical offsets, respectively, with respect to the centre of the image.
Example
./piece_manip.sh --crop 100x100 -o counter1_crop.png
./piece_manip.sh --crop 100x100 -o counter2_crop.png
Drop
./piece_manip.sh --drop [SIZE [COLOUR [FADE [OPACITY]]]] INPUT ...
Add a COLOUR
-coloured drop-shadow to images. If COLOUR
is not specified, it defaults to gray7
. If FADE
is positive, then the shadow will fade of that many pixels. OPACITY
sets the opacity of the start of the drop-shadow. SIZE
defaults to 4
, FADE
to 0, and OPACITY
to 60.
Example
./piece_manip.sh --drop 2 "#11111e" 4 counter1.png -o counter1_drop.png
./piece_manip.sh --drop 2 "#11111e" 4 counter2.png -o counter2_drop.png
Expand
./piece_manip.sh --expand SIZE INPUT ...
Add a SIZE
pixels to the top and bottom of the images. The colours of these extra pixels are sampled from the edge of the image. In some sense, this is the reverse of --shave
.
Example
./piece_manip.sh --expand 2 counter1.png -o counter1_expand.png
./piece_manip.sh --expand 2 counter2.png -o counter2_expand.png
Outline
./piece_manip.sh --outline [COLOUR] INPUT ...
Add a COLOUR
-coloured outline to images. If COLOUR
is not specified, it defaults to black
.
Example
./piece_manip.sh --outline blue counter1.png -o counter1_outline.png
./piece_manip.sh --outline blue counter2.png -o counter2_outline.png
Rounded
./piece_manip.sh --rounded [SIZE] INPUT ...
Make the corners of the images rounded. The radius is set by SIZE. SIZE defaults to 16
.
Example
./piece_manip.sh --rounded 16 -o counter1_rounded.png
./piece_manip.sh --rounded 16 -o counter2_rounded.png
Shade
./piece_manip.sh --shade [SIZE [ANGLE [ELEVATION]]] INPUT ...
Add a smooth bevel to the image of size SIZE
. The shade is drawn as if the light-source is at the angle ANGLE
and elevation ELEVATION
(both in degrees, and defaults to 135 and 30, respectively). Note that ANGLE
is in the range 0
to 360
and ELEVATION
in the range 0
to 90
, though the extremes should be avoided.
Example
./piece_manip.sh --shade 5 -o counter1_shade.png
./piece_manip.sh --shade 5 -o counter2_shade.png
Shave
./piece_manip.sh --shave X Y INPUT ...
Shave off from left and right, top and bottom of the image. X
is the number of pixels to remove both from the left and right edges, while Y
is the number of pixels to remove from the top and bottom edges.
Example
./piece_manip.sh --shave 5 5 -o counter1_shave.png
./piece_manip.sh --shave 5 5 -o counter2_shave.png
Combining manipulations
The above manipulations can be combined. That is, one can specify multiple operations for a single image file. The will then be applied in the order given. Note that the order matters.
Example
./piece_manip.sh \
--bevel 8 \
--rounded 16 \
--outline black \
--drop 2 "#11111e" 4 \
--color 16 \
-o counter1_fancy.png counter1.png
./piece_manip.sh \
--bevel 8 \
--rounded 16 \
--outline black \
--drop 2 "#11111e" 4 \
--color 16 \
-o counter2_fancy.png counter2.png
Note, the option --color 16
reduces the final image size to just over 25% if that option had not been specified, and a roughly 40% of the original image. If instead --color 32
had been specified, then the final size would be roughly 50% or the original image size.
License
The script piece_manip.sh
is licensed under the GNU General Public License version 3, or later. See also LICENSE
.