Skip to main content

ResizeMode

Enum ResizeMode 

Source
#[non_exhaustive]
pub enum ResizeMode { Default, Force, Fill, Shrink, Grow, Percent, Area, }
Expand description

-resize / -thumbnail geometry-modifier suffix.

ImageMagick’s geometry grammar tags the literal WxH with a single trailing character that selects the scaling policy. We honour the six common ones; everything else (%@ combos, gravity flags, …) is a documented follow-up.

The runtime sees the original WxH plus this tag and resolves the final pixel dimensions against the actual source size — most modes can’t be eagerly resolved at parse time because we don’t yet know the source dims.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Default

No suffix — preserve aspect ratio and FIT inside the WxH box (the larger of the two scale factors wins, so neither output dimension exceeds the request). IM’s default geometry policy.

§

Force

WxH! — IGNORE aspect ratio, force the exact WxH dimensions. Equivalent to the original bang = true.

§

Fill

WxH^ — preserve aspect ratio and FILL the WxH box (the smaller of the two scale factors wins, so both output dimensions are at least the request). Common pairing with a follow-up -crop to land on exact WxH.

§

Shrink

WxH> — only resize when the input is LARGER than WxH (otherwise pass through unchanged). IM’s “shrink-only” policy.

§

Grow

WxH< — only resize when the input is SMALLER than WxH (otherwise pass through unchanged). IM’s “enlarge-only” policy.

§

Percent

WxH% — interpret W and H as percentages of the source dimensions (independent X / Y scale). WxH are still parsed as integer percentages by parse_wxh; if only one number is given it applies to both axes (handled at parse time).

§

Area

WxH@ — interpret W*H as the TARGET pixel area; both output dims are scaled by sqrt(target_area / source_area) so the aspect ratio is preserved AND the output area matches the request.

Implementations§

Source§

impl ResizeMode

Source

pub fn split_suffix(s: &str) -> (ResizeMode, &str)

Strip an IM geometry-modifier suffix off WxH. Returns (mode, geometry-without-suffix). No suffix means Default plus the input verbatim. Multiple suffix chars (e.g. WxH^!) are rejected by the args parser layer; here we only peel the LAST one and report what we found.

Source

pub fn as_tag(self) -> &'static str

Lowercase tag string used in JSON params handed to the resize factory. Stable identifiers — codecs that grow geometry-mode awareness can branch off these.

Source

pub fn resolve( self, req_w: u32, req_h: u32, src_w: u32, src_h: u32, ) -> (u32, u32)

Resolve the final (out_w, out_h) for a request of (req_w, req_h) against a source size of (src_w, src_h).

Output is always >= 1 on both axes; clipping to source dims for Shrink / Grow modes happens here so the caller can blindly hand the result to the resize filter without re-checking.

Trait Implementations§

Source§

impl Clone for ResizeMode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ResizeMode

Source§

impl Debug for ResizeMode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResizeMode

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ResizeMode

Source§

impl PartialEq for ResizeMode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ResizeMode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V