Split a PNG Sprite Sheet Into Separate SVG Files
Slice a regular PNG sprite sheet by row, column, margin, and gutter. Trace the cells individually and check that neighboring shapes stay out of each SVG.
On this page
Split the PNG into individual cells before tracing. Start each crop at the correct image margin, use the original cell dimensions, and step across by the cell width plus the gutter. Open the cropped PNGs before converting them to SVG. A trace will follow any piece of a neighboring sprite that gets into the crop.
This works for a regular sheet of flat artwork. If the sprites are tightly packed with different sizes or rotations, use the atlas coordinates from the exporter. For animation frames, retain the frame size and alignment. Artwork designed to keep exact pixels often belongs in PNG. Read the pixel art vectorization example before smoothing intentional stair steps.
Measure the cell and the gutter
A cell is the rectangle reserved for one sprite, including its transparent space. A gutter is the gap between those rectangles. The margin is the offset from the edge of the sheet to the first cell.
| Measurement | Example sheet |
|---|---|
| Sheet size | 328 × 224 px |
| Grid | 3 columns × 2 rows |
| Cell size | 96 × 96 px |
| Left and top margins | 12 px |
| Horizontal and vertical gutters | 8 px |
| Distance from one cell origin to the next | 104 px |
Check the second cell before processing the sheet. Counting everything between two visible shapes as the gutter adds the transparent padding inside each cell. That error accumulates across columns. If the sheet comes with an atlas file, prefer its frame rectangles to measurements by eye.
Crop the six PNG cells
Save the input as sheet.png and run this Python example with Pillow installed. Use your source measurements in place of the example values. Pillow accepts a box in the order left, upper, right, lower. Pillow cropping documentation
from pathlib import Path
from PIL import Image
image = Image.open("sheet.png").convert("RGBA")
rows, columns = 2, 3
cell_width, cell_height = 96, 96
left_margin, top_margin = 12, 12
x_gap, y_gap = 8, 8
output = Path("cells")
output.mkdir(exist_ok=True)
for row in range(rows):
for column in range(columns):
x = left_margin + column * (cell_width + x_gap)
y = top_margin + row * (cell_height + y_gap)
right = x + cell_width
bottom = y + cell_height
if right > image.width or bottom > image.height:
raise ValueError(f"Cell {row}, {column} is outside the image")
image.crop((x, y, right, bottom)).save(output / f"r{row}-c{column}.png")Keep an unchanged copy of the original sheet. Open the first, second, and last tiles. On a transparent sheet, use a contrasting background so an isolated edge pixel is visible. PNG supports alpha transparency; keeping it lets you see the empty region rather than flattening it into the sprite. W3C PNG specification
Trace each clean tile on its own
For simple, single-color shapes on transparency, use the alpha channel as a mask. Mark the sprite as black and the background as white before passing it to a monochrome tracer. Use a color-aware vectorizer for artwork where distinct fills matter. If a faint edge is intentional, test a crop before applying the same cutoff to every tile.
With Pillow still available, run this Python block from the same folder. It writes one PBM mask per cropped PNG. Pixels at or above alpha 128 become black.
from pathlib import Path
from PIL import Image
mask_dir = Path("masks")
mask_dir.mkdir(exist_ok=True)
for tile in sorted(Path("cells").glob("*.png")):
with Image.open(tile) as png:
alpha = png.convert("RGBA").getchannel("A")
mask = alpha.point(lambda value: 0 if value >= 128 else 255)
mask.convert("1", dither=Image.Dither.NONE).save(
mask_dir / f"{tile.stem}.pbm"
)With Potrace on your path, run this in a shell from the same folder. The output names match the row and column of each PNG crop. Potrace manual
mkdir -p svg
for mask in masks/*.pbm; do
name=$(basename "$mask" .pbm)
potrace --svg --turdsize 0 --output "svg/$name.svg" "$mask"
doneWith Potrace 1.16, each of the six correct cells produced one path and no embedded bitmap. We kept speckle removal at zero so the shifted crop would still expose any extra shape.

The shifted crop lost part of the first sprite and included a sliver of the second. Both PNG crops had the same 96 × 96 dimensions. Correct file dimensions alone provide no assurance that the boundaries are right.
Inspect the SVG before replacing the PNG
- Open each SVG on a contrasting background. Verify that no neighbor fragments remain and the smallest intended marks survived.
- Inspect the SVG in a vector editor. A source that looks sharp may still be an embedded raster image.
- Keep a consistent coordinate frame if the sprites need to line up across states or animation frames. All six test traces used a 96 × 96 SVG
viewBox. Check that frame before trimming any transparent margins. The viewBox defines the coordinate rectangle used to position the artwork. W3C SVG coordinate systems
If the output is meant to be a single web SVG sprite for reuse, combine the approved icons into an SVG symbol sprite after checking the individual files.
FAQ
Why does my traced sprite include bits of another frame?
Check the left and top margins and include the gutter in the step between cells. Fix the crop on the PNG sheet first, then trace that cell again.
Can I turn every game sprite into SVG?
Flat silhouettes and icons are good candidates for this workflow. Keep a raster image when exact pixels, textured shading, or a painted effect matter more than editable paths.
Do I need to trim transparent margins from every SVG?
Keep the same frame when multiple sprites need to align. Trim a standalone icon only after checking its framing and the expected placement in the receiving app.
Sources
- Pillow — Copying a subrectangle from an image — crop box coordinate order and region extraction.
- W3C — PNG specification — transparency and alpha in a PNG source.
- Potrace — Command-line manual — PBM input, SVG output, and speckle area settings.
- W3C — SVG 2 coordinate systems — the viewBox coordinate rectangle.
When you have separate flat-color PNGs, preview a trace in PerfectVector. Start with one tile, compare it against the PNG, and check the frame and edges before tracing the rest.
More from the blog
Recover a Logo From Your Website Without a Screenshot
Find the logo file your website already serves. Recover an SVG or a larger PNG from the header and check its dimensions, artwork, and transparency.
Inline SVG vs img: Choose How Your Artwork Behaves
Compare the same SVG as an image and inline markup. Test CSS color control, sizing, accessible names, and reuse before choosing how to embed your artwork.


