#[non_exhaustive]pub enum ConstraintMode {
Distort,
Fit,
Within,
FitCrop,
WithinCrop,
FitPad,
WithinPad,
PadWithin,
AspectCrop,
}Expand description
How to fit a source image into target dimensions.
Source 4:3, Target 1:1 (square):
Fit Within FitCrop FitPad
┌───┐ ┌───┐ ┌───┐ ┌─────┐
│ │ │ │ │ █ │ │ │
│ │ │ │ │ █ │ │ ███ │
│ │ │ │(smaller) │ █ │ │ │
└───┘ └───┘ └───┘ └─────┘
exact size ≤ source fills+crops fits+padsVariants (Non-exhaustive)§
This enum is marked as non-exhaustive
Distort
Scale to exact target dimensions, distorting aspect ratio.
Fit
Scale to fit within target, preserving aspect ratio.
Will upscale small images — use Within to prevent this.
Output may be smaller than target on one axis.
Within
Like Fit, but never upscales.
Images already smaller than target stay their original size.
FitCrop
Scale to fill target, crop overflow to exact target dimensions. Preserves aspect ratio. Upscales or downscales as needed.
WithinCrop
Like FitCrop, but never upscales.
FitPad
Scale to fit within target, pad to exact target dimensions. Preserves aspect ratio. Upscales or downscales as needed.
WithinPad
Like FitPad, but never upscales.
When the source fits within the target on both axes, the image passes
through at its original size (identity — no scaling, no padding, no
canvas expansion). When the source exceeds the target on either axis,
it is downscaled to fit inside the target and centered on the canvas.
PadWithin
Like WithinPad, but always pads to target canvas.
Never upscales. Downscales to fit if the source exceeds target on either axis. The canvas is always the target dimensions, even when the image is smaller — the image is centered (or gravity-positioned) on the canvas.
Compare with WithinPad, which returns identity (no canvas, no padding)
when the source fits within the target.
AspectCrop
Crop to target aspect ratio without any scaling.
Trait Implementations§
Source§impl Clone for ConstraintMode
impl Clone for ConstraintMode
Source§fn clone(&self) -> ConstraintMode
fn clone(&self) -> ConstraintMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more