Studio Yotsuba
Back to Node List

Fit to Canvas

fit_to_canvas

Fit image to target canvas size with various modes

Reviewed
Guide available

Input Ports

NameTypeDescription
Image
input
Image
Required
Input image

Output Ports

NameTypeDescription
Image
output
Image
Fitted image

Parameters

NameTypeDefaultRangeDescription / Options
Width
width
Int
321–4096

Target canvas width

Height
height
Int
321–4096

Target canvas height

Fit Mode
fit_mode
Enum
Contain—

How to fit the image to the canvas

  • ContainContain
    Fit within canvas, preserving aspect ratio. May have empty space
  • CoverCover
    Fill canvas, preserving aspect ratio. Clips overflow
  • StretchStretch
    Stretch to fill canvas, ignoring aspect ratio
  • NoneNone
    No resize, just place on canvas
Alignment
anchor
Enum
Center—

Image placement when canvas has empty space

  • Top-LeftTop-Left
  • Top-CenterTop-Center
  • Top-RightTop-Right
  • Center-LeftCenter-Left
  • CenterCenter
  • Center-RightCenter-Right
  • Bottom-LeftBottom-Left
  • Bottom-CenterBottom-Center
  • Bottom-RightBottom-Right
Scale Method
sampling
Enum
NearestNeighbor—

Scaling method

  • NearestNeighborNearestNeighbor
    Scale to exact fit size
  • IntegerOnlyIntegerOnly
    Use an integer factor for enlargement or an integer reciprocal for reduction — pixel perfect

Overview

Fits images of different sizes into a specified canvas. Using the same idea as CSS object-fit (Contain / Cover / Stretch / None), it standardizes assets in one node—for example, making every image 64×64 and aligning it bottom-center.

Usage tips

  • The go-to pixel-art settings are fit_mode = Contain and sampling = IntegerOnly. Enlargement uses factors such as 2× or 3×; reduction uses reciprocals such as 1/2 or 1/3 and always keeps the whole image in the canvas.
  • This is useful before building a sprite sheet. Align frames of different sizes with None + Bottom-Center to create an animation anchored at the feet.
  • For only cropping or adding margins, use canvas_resize; for free-form scaling alone, use content_resize.

Related nodes

  • canvas_resize — simple canvas changes with fixed placement
  • content_resize / pixel_scale — scaling itself
  • sprite_sheet_pack — a common destination after standardization

Fit modes

Mode Label Effect
Contain Contain Largest size that fits within the canvas; preserves aspect ratio and leaves margins
Cover Cover Smallest size that covers the canvas; preserves aspect ratio and clips overflow
Stretch Stretch Ignores the aspect ratio and stretches to fill the canvas
None Placement only Does not resize; only places the image on the specified canvas

Scale methods

Method Label Description
NearestNeighbor Nearest neighbor Scales exactly to the fitted dimensions
IntegerOnly Integer only Enlarges by the largest integer factor (1×, 2×, 3×...) or reduces by the largest fitting integer reciprocal (1/2, 1/3...)

IntegerOnly is especially useful for pixel art. It avoids fractional enlargement, and when the input is larger than the canvas it chooses 1/2, 1/3, and so on until the whole image fits, so Contain never crops it.

Examples

Fit pixel art into a preview canvas

Place 16×16 pixel art with width: 64, height: 64, fit_mode: Contain, and sampling: IntegerOnly → 4× scaling to 64×64.

Make a background image cover the canvas

Place a 48×32 background with width: 64, height: 64, fit_mode: Cover, and anchor: Center → preserve the aspect ratio, cover the canvas, and clip the overflow.

Place a sprite on a canvas

Place a 16×16 sprite with width: 32, height: 32, fit_mode: None, and anchor: Bottom-Center → align it bottom-center with margins around it.

Back to Node List