# Tool to snip hexagon-shaped counters from an image?

**URL:** <https://forum.vassalengine.org/t/tool-to-snip-hexagon-shaped-counters-from-an-image/90092>\
**Category:** Module Design\
**Created:** [April 24, 2026, 1:39am UTC](https://forum.vassalengine.org/t/tool-to-snip-hexagon-shaped-counters-from-an-image/90092 "2026-04-24T01:39:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![easyalias](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/easyalias/32/4164_2.png) [@easyalias](https://forum.vassalengine.org/u/easyalias)\
**Post date:** [April 24, 2026, 1:39am UTC](https://forum.vassalengine.org/t/tool-to-snip-hexagon-shaped-counters-from-an-image/90092/1 "2026-04-24T01:39:56Z")

</div>

For a game that uses counters which are hexagons, not squares, is there a tool that could slap a hexagon grid over an image of a bunch of them and automatically generate the individual piece images?

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [April 25, 2026, 1:43pm UTC](https://forum.vassalengine.org/t/tool-to-snip-hexagon-shaped-counters-from-an-image/90092/2 "2026-04-25T13:43:37Z")

</div>

Try something like the Python script below:

```py
#!/usr/bin/env python

def mask(image):
    from PIL import Image, ImageDraw

    h = image.height
    w = image.width
    mask = Image.new('L', (image.size), 0)
    draw = ImageDraw.Draw(mask)
    draw.polygon([[w, h/2],
                  [w*3/4,0],
                  [w*1/4,0],
                  [0, h/2],
                  [w*1/4,h],
                  [w*3/4,h],
                  [w, h/2]],
                 fill=255)

    image.putalpha(mask)
    

def hexCoords(col, row, width, height, stagger, offset=(0,0)):
    from numpy import asarray
    hoff = (-.5 if stagger else 1) * (col % 2)
    return asarray(
        [[offset[0] + col * width,
          offset[1] + (row + hoff) * height]])

def run(filename,
        offset,
        width,
        height,
        stagger,
        prefix=''):
    from PIL import Image

    image = Image.open(filename)
    hw = 4 * width / 3
    hh = height
    fullw = image.width
    fullh = image.height
    ncol = int((fullw + hw // 2 - offset[0]) // width)
    nrow = int((fullh + hh // 2 - offset[1]) // height)
    
    for col in range(0,ncol):
        for row in range(0,nrow):
            x, y = hexCoords(col, row, width, height, stagger, offset)[0]
            ulx = int(x - hw / 2)
            uly = int(y - hh / 2)
            lrx = ulx + hw
            lry = uly + hh
            crop = image.crop([ulx, uly, lrx, lry])
            mask(crop)
            crop.save(f'{prefix}{col:02d}{row:02d}.png')

if __name__ == ' __main__':
    from argparse import ArgumentParser, FileType
    ap = ArgumentParser(description='Extract Hex-shaped images')
    ap.add_argument('input',type=FileType('rb'),help='Image to extract from')
    ap.add_argument('-W','--hex-width', type=float,
                    help='Hex width - Vassal style (3/4 of full width)',
                    default=118 * 3 / 4)
    ap.add_argument('-H','--hex-height',type=float,
                    help='Hex height - Vassal style',
                    default=102.5)
    ap.add_argument('-e','--even-columns',choices=['high','low'],
                    help='Are even columns high or low',
                    default='high')
    ap.add_argument('-x','--x-offset', type=float,
                    help='X offset from top-left of centre of top-left hex',
                    default=118 * 3 / 4),
    ap.add_argument('-y','--y-offset', type=float,
                    help='Y offset from top-left of cenre of top-left hex',
                    default=3 * 102.5 / 2)
    ap.add_argument('-p','--prefix',type=str,default='',
                    help='Prefix on output files')

    args = ap.parse_args()

    run(args.input,
        (args.x_offset,args.y_offset),
        args.hex_width, args.hex_height,
        args.even_columns == 'high',
        args.prefix)

#
# EOF
#

```

- it requires Python
- It requires `pillow` - install with `pip install pillow`
- It does not deal with rotated images
- output images have transparent background
- support various options: Run with the `--help` option to see them
- and probably some other bugs too 😄

Using it one an image like

 ![image](https://forum.vassalengine.org/uploads/default/original/2X/2/284e5397a95cddefa5e8b2af398bcbcf3d62f15a.png)

yields images like

| | | | | |
| --- | --- | --- | --- | --- |
| ![foo_0000](https://forum.vassalengine.org/uploads/default/original/2X/d/d7a9d29cf57ef96e5023014a926f736d66165008.png) | ![foo_0100](https://forum.vassalengine.org/uploads/default/original/2X/8/8c4034fc771bba15eea9a5d65282a4cdbe10887d.png) | ![foo_0200](https://forum.vassalengine.org/uploads/default/original/2X/c/ca62ca1b4cafb4afc3be9d6e4a20752a64413d74.png) | | |
| ![foo_0001](https://forum.vassalengine.org/uploads/default/original/2X/6/6c29bbdb2fb56fec6ff0aa9474e04aa6120d428d.png) | ![foo_0101](https://forum.vassalengine.org/uploads/default/original/2X/2/2925962f5c70b12cd5bcffbd817a93e7f5d7908e.png) | ![foo_0201](https://forum.vassalengine.org/uploads/default/original/2X/f/f6bc3fede5f6cdacc783c9632b0d93fdbeaa64c6.png) | | |
| ![foo_0002](https://forum.vassalengine.org/uploads/default/original/2X/8/86a9272e0ec8f5c26c556c1a42fb96eff1df9bd1.png) | ![foo_0102](https://forum.vassalengine.org/uploads/default/original/2X/f/f9b15e37f6fcf20e1a19eff4c6cdae95425654e4.png) | ![foo_0202](https://forum.vassalengine.org/uploads/default/original/2X/a/a7e8990d9c25087248ef99daf6d39d8aa0833e5d.png) | | |

Yours,  
_Christian_

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [April 26, 2026, 12:03pm UTC](https://forum.vassalengine.org/t/tool-to-snip-hexagon-shaped-counters-from-an-image/90092/3 "2026-04-26T12:03:13Z")

</div>

> [@cholmcc](#):
>
> Python script below

See also [here](https://gitlab.com/wargames_tex/vassal_my_contrib/-/tree/master/hexclip?ref_type=heads) for an updated, more capable, script.

Yours,  
_Christian_
