Page 1 of 1

Extract tiles in a grid from a single PNG?

Posted: 2020-11-10T21:05:12-07:00
by tabicat
I know questions like this get asked a lot, but I haven't been able to find an answer to my specific use-case.

I frequently have to extract rectangular tile images that are laid out in a grid in a single PNG. The image contains a grid of M x N tiles. The upper-left corner of the upper-left tile in the grid is at offset (X, Y) in pixels. Each tile is WxH pixels in size. In addition, each tile in a row is DX pixels from upper-left corner to upper-left corner (so that DX >= W), and each column is DY pixels below the one above it (DY >= H).

In this picture, M=3 and N=2

Give all these variables, could someone please tell me what command to use to extract the six tiles into their own PNG files? I'm assuming it's using the 'convert' command.