According to the GraphicsMagick man page I can create multiple tiles from an image by using -crop
without an offset:
If the x and y offsets are omitted, a set of tiles of the specified geometry, covering the entire input image, is generated. The rightmost tiles and the bottom tiles are smaller if the specified geometry extends beyond the dimensions of the input image.
So I ran the following commands (under Linux):
gm convert -crop 256x256 input.png tile # => a single file called tile
gm convert -crop 256x256 input.png tile.png # => a single file called tile.png
How do I specify an output so that multiple images are created?
gm convert -crop 256x256 input.png +adjoin tile%04d.png
The +adjoin is the key.
From the Files and Formats section of the manual:
Single images are written with the filename you specify. However, multi-part images (e.g., a multi-page PostScript document with +adjoin specified) may be written with the scene number included as part of the filename. In order to include the scene number in the filename, it is necessary to include a printf-style
%d
format specification in the file name and use the +adjoin option. For example,image%02d.miff
writes files
image00.miff
,image01.miff
, etc. Only a single specification is allowed within an output filename. If more than one specification is present, it will be ignored. It is best to embed the scene number in the base part of the file name, not in the extension, because the extension will not be a recognizeable image type.
and the adjoin section:
Use +adjoin to force saving multiple frames to multiple numbered files. If +adjoin is used, then the output filename must include a printf style formatting specification for the numeric part of the filename. For example,
image%02d.miff