How to Crop an Image into Tiles with ImageMagick?
This article provides a quick overview and practical guide on how to
use the ImageMagick convert command to slice a single image
into a grid of smaller, equal-sized tiles. You will learn the exact
syntax for the -crop geometry option, how to handle image
positioning, and how to automatically number the outputted image
files.
The ImageMagick Slicing Syntax
To split an image into a grid of smaller tiles, you use the
convert command paired with the -crop option.
The basic syntax requires you to define the target width and height of
the tiles, followed by a percentage sign or an @ symbol
depending on how you want to split the image.
Here is the standard command to slice an image into specific pixel dimensions:
convert input.jpg -crop 100x100 +repage tile_%d.jpgSyntax Breakdown
input.jpg: The path to your original source image.-crop 100x100: The directive that tells ImageMagick to cut the image into tiles that are 100 pixels wide by 100 pixels high.+repage: A crucial option that removes the virtual canvas offset information from the newly created tiles. Without this, some image viewers might still try to render the tiles at their original positions on the canvas.tile_%d.jpg: The output file naming convention. The%dacts as a placeholder that automatically inserts a sequential number (starting at 0) for each tile generated, preventing the files from overwriting one another.
Alternative Slicing: Grid by Equal Segments
If you do not know the exact pixel dimensions but instead want to
divide the image into an equal number of rows and columns (for example,
a 3x3 grid), you can add the @ symbol to your geometry
arguments.
convert input.jpg -crop 3x3@ +repage tile_%02d.jpgIn this variation, 3x3@ tells ImageMagick to divide the
image into 3 equal columns and 3 equal rows, resulting in 9 total tiles.
The %02d format string ensures that the output filenames
use two-digit, zero-padded numbering (e.g., tile_00.jpg,
tile_01.jpg), which keeps your file directory cleanly
organized.