Pikkola Sprite, tool No. 79

Many pictures, one request.

Drop in the frames, choose a sheet width and a gap, and get one PNG with the CSS that addresses every frame by coordinates. The reverse works too: hand it a sheet you already ship, say how many rows and columns it has, and read the coordinates back out.

1
request
2
ways to work
0
uploads

The bench

Pack, or take apart

A sprite sheet trades one request for arithmetic: every frame becomes a background position and a width, and the arithmetic is the thing that goes wrong. The numbers under the preview are the ones the CSS uses.

Frames

Drop PNG, JPEG, WebP, GIF or SVG files

    No frames yet.

    Pack the frames to see the sheet.

    Sheet
    -
    Frames
    0
    Fill
    -
    PNG size
    -

    One request instead of forty

    An HTTP/2 connection makes many small requests cheaper than it used to be, and it does not make them free. A sheet is still the right shape for a set of icons that always appear together, and it is still a coordinate table that has to be right.

    01

    Rows, sorted by height

    The tallest frame goes first and every frame is placed on the first row it fits, which is the shelf algorithm. It is not the tightest packing possible and it is the one whose output a person can predict: the same frames in the same order always produce the same sheet.

    02

    The sheet is a canvas

    Frames are drawn in order onto a canvas at their own size, and the PNG is the canvas encoded by the browser. Transparent edges stay transparent, so a sheet can carry a shadow that spills past the frame it belongs to only if the gap is wide enough.

    03

    The coordinates come from the layout

    Every CSS rule is written from the same placed rectangle the drawing used, so a background position cannot disagree with the picture. A single-row sheet is written with background-position-x only, which is shorter and is the form most icon sets use.

    What the packer does, and what it will not

    A sprite sheet is a build artefact, and the rules that make it safe are the ones that keep it reproducible and keep the CSS honest.

    Part of the sheet What this page does What it will not do
    Frame order Tallest first, then the order you added them Optimise the packing by trying several layouts
    Gaps Adds the gap you choose on both axes Bleed a frame into its neighbour: that is a texture-tool job
    Colour Keeps the pixels as the browser decoded them Quantise or compress the palette: the PNG encoder decides
    Retina Packs at the size the file has Produce a 2x sheet from 1x art: supply the 2x files
    CSS units Pixels, with the frame size in the same rule Emit rem or a framework's class syntax
    Slicing Divides the sheet into a grid you describe Find frames in an unlabelled sheet: without a rule there is nothing to find

    The PNG is encoded by the browser's own encoder, so its byte size depends on the browser rather than on this page. The sheet dimensions, the layout and every coordinate do not.

    Field guide

    What a sprite sheet is actually for

    A sheet is a cache decision written as an image. It pays when the frames always appear together and it costs when one of them changes, and the coordinate arithmetic in between is where most of the bugs live.

    One request, one cache entry

    Forty small icons are forty round trips on a cold connection and forty cache entries to invalidate. A sheet is one of each, which is why icon systems still use it even though HTTP/2 multiplexes requests: multiplexing removes the ordering cost, not the per-request overhead of headers, TLS records and cache lookups. The trade is that changing one icon changes the file, so the browser refetches all forty. That is a good trade for a set that changes once a release and a bad one for a set that changes weekly.

    The shelf layout and why it is predictable

    Frames are sorted by height, tallest first, and each one is placed on the first row where it fits under the width you chose. Every row starts at the left edge and grows until the next frame will not fit, then a new row begins below the tallest frame in the previous one. The result wastes space in the ragged right edge of each row, which is why a sheet is rarely more than about seventy percent filled. The alternative, a search over orderings that tries to close those gaps, produces a slightly smaller file and a build that cannot be reproduced without recording the search itself.

    DecisionWhat it changesWhat it costs
    Frames sorted by heightShorter rows, less wasteFrame order in the CSS is not your order
    A gap between framesRoom for a shadow or an extruded edgeA few percent of the sheet
    Power-of-two heightCompatibility with old texture rulesTransparent rows at the bottom
    A wider sheetFewer rows, lower heightWider than the device's maximum texture, which is a real limit on old phones

    Retina is a second sheet, not a scale factor

    A 2x sheet is not this sheet enlarged: it is the same layout drawn from the 2x files, and it is addressed with the same coordinates multiplied by two. If you only have 1x art, packing it and scaling the result gives a soft image with the same pixel count as the original, which is not a retina asset. The usual arrangement is two sheets and a media query or an image-set() in CSS, and both of them need the coordinates to be identical, which is why the layout has to be deterministic.

    Slicing is the reverse arithmetic

    A sheet that already ships has its frames at positions somebody else decided. Dividing it into a grid is the only way to recover them without a manifest, and it works only when the frames are evenly sized: a sheet with rows of different heights cannot be read by rows and columns alone. The offset field exists because a texture tool often adds a one-pixel transparent border, which shifts every cell by one and is invisible until a background position is off by exactly one pixel.

    Before the frames are packed, Pikkola Image resizes and converts them, and Pikkola SVG is where a vector becomes a small raster worth putting in a sheet.

    Questions

    Are my images uploaded?

    No. A dropped file is read into an image object in this tab and drawn onto a canvas. Nothing is sent, and the page makes no request after it loads except the cookieless page-view count.

    Why is my sheet not the tightest possible?

    Because the packer uses shelves rather than a search. A tighter packing needs a search over orderings, which makes the output depend on a timeout or an iteration count, and a build artefact that changes between runs is worse than one that is a few percent larger.

    Why does the PNG weigh more than my files added up?

    Three reasons: the sheet is one image with a lot of transparent area, PNG compresses each row against the previous one and a sprite sheet has very different rows, and the browser's encoder is set for speed rather than for size. Running the file through a PNG optimiser afterwards is the usual next step.

    Can I use this for a CSS animation?

    Yes, and a single-row sheet is the easiest case: animate background-position-x from 0 to the negative of the sheet width, in steps equal to the frame count. The one-row CSS block this page writes is exactly that layout, and the frame count is in the stats.

    What does the slicer do with an offset?

    It moves the grid inwards from the top left by that many pixels before dividing it, which is how a sheet exported with a one-pixel border is read correctly. The cell size is computed after the offset, so the last column can be a pixel narrower than the rest; the CSS uses each cell's own width rather than one shared number.