Skip to main content

OutputResolution

Enum OutputResolution 

Source
pub enum OutputResolution {
    Original,
    Width2560,
    Width1080,
    Custom(u32),
}
Expand description

Controls the output resolution applied before AVIF encoding.

Set this on Config via Config::output_resolutions to produce one or more outputs at different sizes from a single decode pass.

§Downscale-only

When the decoded image is already at or below the target width the pixels are passed through unchanged — img4avif never upscales.

§Aspect ratio

The height is always scaled proportionally so the image is never cropped or distorted.

§Example

use img4avif::{Config, Converter, OutputResolution};

// Produce only the 1080-wide variant.
let config = Config::default()
    .output_resolutions(vec![OutputResolution::Width1080]);
let converter = Converter::new(config)?;
let avif_1080 = converter.convert(&std::fs::read("photo.jpg")?)?;
std::fs::write("photo_1080.avif", avif_1080)?;

Variants§

§

Original

Preserve the original image dimensions (no resize).

§

Width2560

Shrink so the width is at most 2560 pixels, preserving the aspect ratio. Images already ≤ 2560 px wide are passed through unchanged.

§

Width1080

Shrink so the width is at most 1080 pixels, preserving the aspect ratio. Images already ≤ 1080 px wide are passed through unchanged.

§

Custom(u32)

Shrink so the width is at most the given number of pixels, preserving the aspect ratio. Images already at or below this width are passed through unchanged.

A width of 0 is treated the same as Original — the image is returned at its full size without any resizing. This is a deliberate design choice that makes it safe to derive a target width from arithmetic that could produce zero; callers that want a hard error on zero should validate the value before constructing this variant.

Trait Implementations§

Source§

impl Clone for OutputResolution

Source§

fn clone(&self) -> OutputResolution

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OutputResolution

Source§

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

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

impl Hash for OutputResolution

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for OutputResolution

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for OutputResolution

Source§

impl Eq for OutputResolution

Source§

impl StructuralPartialEq for OutputResolution

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<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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.