Slicing and padding
The build tab of the properties panel contains padding and slicing options, which change the size and shape of exported images. Padding adds space around exported images. Slicing creates stretchable images, like buttons and panels that can be resized to any width or height without distorting their corners.
To show the build tab, select a layer, group, or page, and choose View › Properties › Build.
Further reading: Exporting
Padding #
By default, exported layers and groups are cropped to their visible content — every pixel that isn’t fully transparent, including effects like shadows and blurs. The Padding fields add transparent space to the top, right, bottom, and left of that crop. This is handy when an image needs to be a specific size, or when artwork needs a little breathing room for things like hover states.
Padding is set in document pixels, and it is scaled along with the image. A build task output with a scale of 2 gets twice the padding. The scaled padding is rounded to a whole pixel.
Like most values in Skala, the padding and slice fields can contain expressions and constants.
Pages always export at the size of the document, so padding and slicing have no effect on them.
Slice types #
The Slice type popup menu decides how a layer or group is cropped and sliced when it is exported.
Cropcrops the image to its visible content, then adds the padding. This is the default.Canvasexports the full size of the document, with the layer or group in its place. Padding is ignored.Horizontalcrops likeCrop, then slices the image into left, center, and right sections.Verticalcrops likeCrop, then slices the image into top, center, and bottom sections.Nine Partcrops likeCrop, then slices the image into corners, edges, and a center.
The Slices fields set where the slices are, measured in from each edge of the image, in document pixels. The padding counts as part of the image. The top and bottom fields are available for Vertical and Nine Part, and the left and right fields are available for Horizontal and Nine Part. Slices are scaled and rounded in the same way as padding.
If a layer or group has nothing visible to export, no file is written.
Horizontal and vertical slices #
Sliced images are exported as a single, compact image. The parts that should stay the same size are kept, and the stretchable center is collapsed down to a single pixel. Your app or website can then stretch that center pixel to make the image any size.
For example, imagine a button that is 100×44 pixels, with left and right slices of 12. With the Horizontal slice type, the exported image keeps the 12 pixel wide left and right ends, and one pixel column from the middle — so the image is 25×44 pixels. At a scale of 2, it’s 49×88 pixels (24 + 1 + 24 wide).
Because the center is a single pixel, sliced images can be stretched, but not tiled. A slice of 0 is fine, and means that side has no fixed end.
If the slices are so large that they leave no center, that direction is exported without slicing, and the build reports a warning.
Nine-part slices #
The Nine Part slice type slices both directions at once. The four corners stay the same size, the top and bottom edges stretch horizontally, the left and right edges stretch vertically, and the center stretches in both directions. It’s perfect for panels, text fields, and buttons that need to change width and height.
The exported image keeps the corners, and collapses the center to one pixel in both directions. A 100×60 pixel panel with slices of 16 on every side exports as a 33×33 pixel image.
JSON sidecar files #
Every sliced image is exported with a JSON file next to it, describing where the slices are. It’s named after the full file name of the image, with .json added, so button@2x.png gets a sidecar called button@2x.png.json. If the image can’t be written, neither is its sidecar.
{
"version": 1,
"image": "button@2x.png",
"scale": 2,
"size": { "width": 41, "height": 41 },
"type": "ninePart",
"capInsets": { "left": 20, "top": 20, "right": 20, "bottom": 20 },
"center": { "x": 20, "y": 20, "width": 1, "height": 1 }
}
versionis the version of the sidecar format, which is currently1.imageis the file name of the exported image.scaleis the scale of the build task output that made the image.sizeis the size of the exported image.typeishorizontal,vertical, orninePart.capInsetsare the sizes of the fixed ends, measured in from each edge. Directions that aren’t sliced have insets of0.centeris the rectangle of the stretchable center.
All values are in pixels of the exported image, measured from the top left. Divide by scale to convert to points. For example, the cap insets above are 20 pixels in a 2× image, which is 10 points. The capInsets values map directly to cap insets on iOS and macOS, and slice values for CSS border-image.
When a direction was exported without slicing, because its slices left no center, its insets are adjusted so that the center is still one pixel.