The QA grid arrived as one PNG. Here's how I split an image into tiles now
Last Tuesday a designer dropped a single PNG into the documentation pull request: a 2-row by 4-column grid of UI states. Empty, loading, error, success, and four close variations. The troubleshooting page needed each sta
Last Tuesday a designer dropped a single PNG into the documentation pull request: a 2-row by 4-column grid of UI states. Empty, loading, error, success, and four close variations. The troubleshooting page needed each state next to its own short note. I almost pasted the contact sheet in as-is. That would have been easy, and it would have been the wrong artifact. Readers would have had to hunt inside one wide image for the frame that matched their screen. I had to split an image into the eight files the Markdown was actually going to reference.
A contact sheet is a delivery format, not a docs asset
I am not against the grid itself. For a design review, one sheet is often the right thing to send: you can see the states together and talk about consistency. The problem starts when that same file becomes the only image in a public page.
A docs reader is usually looking for one condition. They want the error state, or the empty state, not a poster of every state at once. If the figure is a grid, the caption has to do too much work: βsecond row, third cell.β That instruction ages badly. The next time a designer adds a ninth state, the coordinates shift and the prose is wrong.
A contact sheet is also awkward to update in the repository. If only the error illustration changes, you have to rebuild the whole grid or live with a stale cell. Individual files let you replace one path. That is the habit I want in a docs PR: each figure points at one file, and the sheet, if we keep it at all, stays in an archive folder the page does not use.
Count the grid before you cut anything
The mistake I have made more than once is opening a crop tool and guessing. The sheet looks like βabout four across.β Then one tile eats a sliver of the next panel, or every tile carries a strip of the gutter.
I now treat the count as a separate step. I look at the file and write down the number of columns and the number of rows. I look at the gaps between cells. I look at the outer margin. If the cells are not the same size, an equal grid will slice through a panel. If there is a wide gutter, that gutter will show up in the tiles unless I deal with it first. If the whole grid sits inside a padded border, the edge tiles will be heavier on one side than the others.
A quick check of the source dimensions helps:
mkdir -p docs/states
magick identify -format "%f %wx%h\n" qa-states.png
If the width does not divide evenly by the column count, or the height does not divide evenly by the row count, I stop. I either go back to the person who made the sheet and ask for a version with even cells, or I crop the extra margin off the source before I do anything else. I would rather fix the input than invent eight slightly different tile sizes and hope nobody notices.
The same planning applies when the file is not a grid. A horizontal filmstrip of onboarding steps is just one row and N columns, or a set of vertical strips. A page that only needs the left and right halves is two columns and one row, or one column and two rows. The arrangement comes first; the command comes second.
The ImageMagick command I actually run
When I already have a terminal and the cells really are equal, I use ImageMagick. I write the tiles into a new folder. I do not overwrite the sheet.
magick qa-states.png -crop 4x2@ +repage +adjoin docs/states/state-%02d.png
magick identify -format "%f %wx%h\n" docs/states/*.png
The 4x2@ syntax means four tiles across and two down, sized so they cover the image. +repage resets the virtual canvas so each output has its own dimensions instead of remembering the original sheet. +adjoin writes a separate file for every tile. Numbering usually runs left to right, top to bottom, starting at zero, so state-00.png is the top-left cell. I do not trust that naming for the docs page β I rename after I have looked at the files β but it is a predictable starting point.
The second identify is the check I used to skip. I want every tile to show the same width and height. If one file is a leftover sliver, the grid did not divide cleanly. If two tiles look like half a panel, I counted the rows or columns wrong. I open the eight files side by side before I git add anything. A command that I never inspect is how a gutter ended up in a README figure last spring.
I keep the original sheet outside the docs path, or in a clearly named archive directory the Markdown is not allowed to reference. The files under docs/states are the only image paths the troubleshooting page may use.
If I only need three of the eight cells, I still cut the whole grid and then copy the ones I need. Throwing away a tile is cheaper than redoing the crop because I grabbed the wrong region by hand.
When I need to split an image without a CLI
Some days I am on a machine where I cannot install ImageMagick, or someone has just dropped the PNG into Slack and I want to see the tiles before I take the file back to the repo. In that case I use a browser tool that can cut a PNG into a row-and-column grid and download only the tiles I need.
The settings that matter are the ones I already planned on paper: the split direction (I use Grid for a state sheet; vertical or horizontal strips when the source is a filmstrip), the column count, and the row count. If I do not need every cell, there is a field for the tiles to download, written as a list such as 1,2,5. I still inspect the preview before I take anything. The original file stays untouched, which is the habit I want: never replace the source, always download a new set, then check the dimensions of those files.
I should say this directly: I work on that tool, and on the broader set of browser image tools next to it. This is the workflow I actually use when I do not have a CLI, not a survey of image splitters, and I am not going to invent a comparison chart. You can edit and preview before signing in; a free account is required to download, save, or share the result. Output can be PNG, which is what I want for UI states that may have a flat background, or another format if the page already standardizes on something else.
After I download, I run identify on the new files anyway, or at least open them and compare widths. A browser preview is not a substitute for looking at the files I am about to commit.
Names, and the Markdown I will actually commit
state-00.png is a fine temporary name and a poor permanent one. Once I have the tiles, I rename them for the page: state-empty.png, state-loading.png, state-error.png, and so on. The Markdown then points at those paths, one figure at a time, with a caption that names the condition, not a cell in a grid.
The short list I keep in the docs repo
I moved this into the contributing guide for our documentation. It is short on purpose.
- Decide whether the page needs individual files, or whether a single sheet is actually the right figure.
- Count the columns and rows. Check gutters, outer margins, and whether the cells are the same size.
- Cut the tiles into a new folder. Do not overwrite the sheet.
- Confirm that every tile has the same dimensions and that no leftover strip appeared.
- Rename the files for the page. Point each figure at one path. Keep the original grid out of the docs tree, or in an archive folder the page does not use.
That is the whole habit. It takes longer to explain than to do, and it would have saved me from publishing a troubleshooting page that asked readers to squint at cell three.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.
