Home/Image Editing, Compression & Conversion Tools/PNG 9-Slice Scale Grid & Border Spec Visualizer

PNG 9-Slice Scale Grid & Border Spec Visualizer

Test 9-slice PNG and SVG scale grids client-side. Configure pixel insets, inspect arbitrary responsive stretch ratios, and export ready-to-paste CSS border-image, Godot, and Unity specs.

Slice Inset Specifications

Drop PNG, WebP, or SVG sprite here, or browse

Local browser processing (Zero server uploads)

Active: scifi-panel-ui.png64 × 64 px
Guide Offsets (Pixels)
px
px
px
px
Edge & Core Behavior
border-image: fill
Real-Time HTML5 Canvas EngineZero Remote Latency

Interactive Visualizer & Slicing Canvas

100%
Source Slice Boundary Editor (Drag Handles)64w × 64h
9-Slice source sprite
T:16
B:16
L:16
R:16
Interactive Slicer View
Target Scaling Resolution240 × 140 px
Arbitrary Aspect Scaled Output Corner Geometry Preserved
STRETCH MODE ACTIVE
Render: 240 × 140 px
Generated Border Spec & Code
/* CSS border-image 9-Slice Definition */
.scalable-panel {
  border-style: solid;
  border-width: 16px 16px 16px 16px;
  border-image-source: url("scifi-panel-ui.png");
  border-image-slice: 16 16 16 16 fill ;
  border-image-repeat: stretch;
  border-image-outset: 0;
}
CSS border-image / Godot NinePatch / Unity Slicedscifi-panel-ui.png

The Architecture of 9-Slice Scaling: Solving Responsive 2D UI Distortion

In modern video games, mobile apps, and responsive web applications, user interface panels rarely adhere to static dimensions. Dialog boxes expand to accommodate variable text strings, inventory windows scale across desktop and mobile displays, and HUD buttons dynamically flex based on localization lengths. Conventional uniform bitmap scaling catastrophically degrades these graphics by stretching rounded corners into oval distortions and smearing drop shadows:

Wdest = L + Wcenter + R  |  Hdest = T + Hcenter + B
Wcenter(dest) = max(0, Wdest − L − R)  |  Hcenter(dest) = max(0, Hdest − T − B)
sx = Wcenter(dest) / Wcenter(src)  |  sy = Hcenter(dest) / Hcenter(src)
Invariant Feasibility Condition: Wdest ≥ L + R  and  Hdest ≥ T + B

4 Invariant Corners

The four outer quadrants (Top-Left, Top-Right, Bottom-Left, Bottom-Right) retain absolute 1:1 pixel fidelity: sx = sy = 1.0. Their coordinate width and height never stretch or compress regardless of container size.

4 1D Elastic Edges

The top and bottom edges scale strictly across the horizontal X-axis (sx = Wcenter(dest) / Wcenter(src), sy = 1.0), while left and right borders scale strictly across the vertical Y-axis (sx = 1.0, sy = Hcenter(dest) / Hcenter(src)).

1 2D Scalable Core

The central patch expands in both X and Y dimensions (sx × sy) using bilinear interpolation or pattern tiling to fill the interior body, or it can be left transparent for window frames.

Slice Coordinate Mathematical Breakdown

Given source bitmap dimensions Wsrc × Hsrc and four border guide margins (T, R, B, L), the graphics engine maps the nine source bounding boxes [sx, sy, sw, sh] into destination target rectangles [dx, dy, dw, dh]:

// Center Zone Coordinate Formulation
SourceCenter = {
sx: L,
sy: T,
sw: Wsrc − L − R,
sh: Hsrc − T − B
};
DestinationCenter = {
dx: L,
dy: T,
dw: Wdest − L − R,
dh: Hdest − T − B
};
Patch ZoneRoleSource Rect [sx, sy, sw, sh]Dest Rect [dx, dy, dw, dh]Scale Deformation
Top-LeftCorner[0, 0, L, T][0, 0, L, T]1:1 Rigid (Invariant)
Top-CenterHorizontal Edge[L, 0, Wsrc − L − R, T][L, 0, Wdest − L − R, T]1D Stretch (X-Axis)
Top-RightCorner[Wsrc − R, 0, R, T][Wdest − R, 0, R, T]1:1 Rigid (Invariant)
Center-LeftVertical Edge[0, T, L, Hsrc − T − B][0, T, L, Hdest − T − B]1D Stretch (Y-Axis)
Center-BodyInterior Fill[L, T, Wsrc − L − R, Hsrc − T − B][L, T, Wdest − L − R, Hdest − T − B]2D Stretch / Tile (X & Y)
Center-RightVertical Edge[Wsrc − R, T, R, Hsrc − T − B][Wdest − R, T, R, Hdest − T − B]1D Stretch (Y-Axis)
Bottom-LeftCorner[0, Hsrc − B, L, B][0, Hdest − B, L, B]1:1 Rigid (Invariant)
Bottom-CenterHorizontal Edge[L, Hsrc − B, Wsrc − L − R, B][L, Hdest − B, Wdest − L − R, B]1D Stretch (X-Axis)
Bottom-RightCorner[Wsrc − R, Hsrc − B, R, B][Wdest − R, Hdest − B, R, B]1:1 Rigid (Invariant)

9-Slice Implementation Across Modern Graphics Engines & Frameworks

While the underlying mathematical coordinate model is uniform across all graphics pipelines, implementation syntax varies between CSS, game engines, and mobile application frameworks:

Platform / EnginePrimary Native APICoordinate Inset OrderKey Feature / Advantage
CSS3 / Web Browsersborder-image-sliceTop, Right, Bottom, Left (Clockwise)Native hardware acceleration without DOM wrapper bloat
Godot Engine 4.xNinePatchRectpatch_margin_left, top, right, bottomBuilt-in horizontal and vertical axis tile modes
Unity 3D / UI ToolkitImage.Type.SlicedLeft, Bottom, Right, Top (Sprite Editor)Batch-renderable mesh generation for canvas draw calls
Android SDKNinePatchDrawable (.9.png)1px perimeter guide line encoded in bitmapSupports independent content padding zones
Apple UIKit / iOSresizableImageWithCapInsetsUIEdgeInsets(top, left, bottom, right)Seamless integration with Auto Layout constraints

Engineering Guidelines for High-Performance 9-Slice Assets

Optimizing sliced bitmap assets requires balancing visual aesthetics with minimal texture memory footprints. Follow these core engineering best practices:

Geometric Inset Feasibility: L + R ≤ Wsrc  |  T + B ≤ Hsrc

Asset Design Best Practices

  • • Minimize Redundant Edge Length: Keep repeatable or stretchable center slices as narrow as 1 to 2 pixels in source art to dramatically reduce download payloads.
  • • Ensure Guide Symmetry on Homogeneous Frames: Set equal margins for top, right, bottom, and left unless an explicit visual anchor (like an arrow tip) requires asymmetry.
  • • Use `image-rendering: pixelated` for Retro Sprites: When developing pixel art games or nostalgic UI themes, enforce nearest-neighbor sampling to avoid unwanted bilinear blur on borders. If your source sprite was authored at tiny native dimensions (such as 16×16px), scale the master asset through our pixel art sprite scaler first to preserve razor-sharp texels prior to configuring slice guide margins.

Critical Pitfalls to Avoid

  • • Overlapping Inset Sums: Never allow the sum of Left + Right slices to exceed the source image width (L + R > Wsrc), or Top + Bottom to exceed image height (T + B > Hsrc), as this breaks raster subdividers.
  • • Omitting the CSS `fill` Keyword: Forgetting the `fill` modifier in `border-image-slice` will leave the interior element hollow, causing background content to show through unexpectedly.
  • • Targeting Smaller Dimensions Than Slice Margins: If a container is smaller than Left + Right or Top + Bottom (Wdest < L + R), corners will overlap or scale down unpredictably unless clamped by min-width rules.

Frequently Asked Questions (FAQ)

What is 9-slice scaling and how does it prevent UI distortion?

9-slice scaling (also known as 9-patch, scale grid, or sliced borders) is a 2D graphics scaling technique that subdivides a bitmap into nine discrete zones: 4 immutable corners, 4 horizontally or vertically stretching edges, and 1 scalable center patch. This enables UI frames, dialog boxes, and buttons to resize dynamically without stretching or blurring rounded bevels and decorative corner art.

How does CSS border-image implement 9-slice scaling natively in browsers?

The CSS border-image specification uses the border-image-slice property to define four inset offsets: top, right, bottom, and left. Adding the "fill" keyword instructs the browser to retain and scale the center patch alongside the outer borders. Paired with border-image-repeat: stretch, repeat, or round, web elements scale flawlessly without multi-nested HTML wrappers.

Are my game sprites or UI graphics uploaded to any remote server?

No. All slice mathematical partitioning, HTML5 Canvas blitting, and code generation execute 100% locally in your browser DOM. Your assets never leave your computer.

What is the difference between stretch, repeat, and round slice modes?

Stretch pulls and interpolates the edge pixels across the target dimension. Repeat tiles the slice repeatedly, potentially clipping partial tiles at borders. Round tiles the slice pattern and mathematically adjusts the pattern width or height slightly so that only whole, unclipped tiles are rendered.

How do I use these exported slices in game engines like Godot and Unity?

In Godot, assign the generated patch margins to a NinePatchRect node. In Unity, open the Sprite Editor on your sliced texture, enter the left, bottom, right, and top pixel borders, and change the UI Image component type to "Sliced".

Can I test non-square and asymmetric 9-slice images?

Yes. This tool supports arbitrary rectangular dimensions. You can set asymmetrical guide values for top, right, bottom, and left to support dialogue balloons with anchor tails, asymmetric tabs, or complex header frames.

Related & Complementary Utilities

Explore more privacy-first client-side web tools.