#[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
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
impl ResizeMode
Sourcepub fn split_suffix(s: &str) -> (ResizeMode, &str)
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.
Sourcepub fn as_tag(self) -> &'static str
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.
Sourcepub fn resolve(
self,
req_w: u32,
req_h: u32,
src_w: u32,
src_h: u32,
) -> (u32, u32)
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
impl Clone for ResizeMode
impl Copy for ResizeMode
Source§impl Debug for ResizeMode
impl Debug for ResizeMode
Source§impl Default for ResizeMode
impl Default for ResizeMode
impl Eq for ResizeMode
Source§impl PartialEq for ResizeMode
impl PartialEq for ResizeMode
impl StructuralPartialEq for ResizeMode
Auto Trait Implementations§
impl Freeze for ResizeMode
impl RefUnwindSafe for ResizeMode
impl Send for ResizeMode
impl Sync for ResizeMode
impl Unpin for ResizeMode
impl UnsafeUnpin for ResizeMode
impl UnwindSafe for ResizeMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.