Zend certified PHP/Magento developer

Export multiple non-adjacent tiles with GIMP or ImageMagik or other tools

Tl;dr: looking for a tool or script that can export disjoint cookie-cutter squares from a larger image.

Imagine that you want a set of tiles on your kitchen wall that make up a larger image. To be completely accurate, you need to not just slice the source image into individual tiles, but also discard the grid of strips which will be covered by the grout, so that the proportions of the assembled mosaic are correct.

Consider the following sample image:

Image of two sugar skulls on a floral background, with a regular grid of red lines superimposed.

If I flatten the image and clear the red lines, I end up with a regularly spaced set of 512×512 squares. (The horizontal gutters are bigger than the vertical ones.)

My current workflow is laborious – I export an image from my many-layered source file, select and clear the red lines, and then use fuzzy select with max threshold to grab each tile and paste it into a temp window to export. (A previous workflow had me selecting 512×512 squares counted out and aligned by hand. Also tedious, and error-prone.)

I have no control over the way the images are displayed in the final application; all I can do is optimize on my end:

Two sugar skulls on a floral background, behind a mask with evenly spaced circles.

What tools and scripts can do what I need? (Is there a Python library with useful functions, perhaps?)