Rust

options

Module

The values the operations take: gravities, focal points, output formats and resource limits.

Contents

use utopia_image::FocalPoint;
Rust
pub struct FocalPoint

A focal point: the spot a crop keeps in view, as fractions of the width and height (0.0..=1.0).

Rust
use utopia_image::FocalPoint;

let point = FocalPoint::new(0.75, 0.5)?;
assert_eq!((point.x(), point.y()), (0.75, 0.5));
assert!(FocalPoint::new(1.1, 0.5).is_err());
assert!(FocalPoint::from_parts(Some(0.5), None).is_err());
assert_eq!(FocalPoint::from_parts(None, None)?, None);
use utopia_image::Gravity;
Rust
pub enum Gravity

Which part of the image a crop keeps.

Rust
use utopia_image::Gravity;

assert_eq!(Gravity::from_name("top-left"), Some(Gravity::TopLeft));
assert_eq!(Gravity::TopLeft.name(), "top-left");
assert_eq!(Gravity::ALL.len(), 9);
use utopia_image::OutputFormat;
Rust
pub enum OutputFormat

An output format.

Rust
use utopia_image::OutputFormat;

assert_eq!("jpeg".parse::<OutputFormat>()?, OutputFormat::Jpeg);
assert_eq!("bmp".parse::<OutputFormat>().unwrap_err().to_string(), "Invalid output type given");
Also implements FromStr.
use utopia_image::Resource;
Rust
pub enum Resource

A resource ImageMagick limits.

use utopia_image::set_resource_limit;
Rust
pub fn set_resource_limit(resource: Resource, value: i64)

Sets a process-wide resource limit.

Rust keeps every frame in memory and resizes on the calling thread, so the limits are recorded for callers to read back (to bound concurrency, say) rather than switching pixels to a disk cache as ImageMagick does. A negative value is stored as zero.

Rust
use utopia_image::{Resource, set_resource_limit};

set_resource_limit(Resource::Memory, 64 * 1024 * 1024);
assert_eq!(Resource::Memory.limit(), 64 * 1024 * 1024);
Rust
pub const MAX_DIMENSION: u64 = 50_000

The largest width or height of an image (ImageMagick's width and height policy in Appwrite's image).