#[non_exhaustive]pub struct EncodeOptions {Show 13 fields
pub quality: u8,
pub lossless: bool,
pub effort: Option<u8>,
pub compression_level: Option<u8>,
pub palette: bool,
pub colours: Option<u16>,
pub dither: Option<f32>,
pub alpha_quality: u8,
pub near_lossless: bool,
pub chroma_subsampling: Option<ChromaSubsampling>,
pub keep_exif: bool,
pub keep_xmp: bool,
pub progressive: bool,
}Expand description
Encoder tuning shared across formats.
Fields that a format has no notion of are ignored by that format rather than rejected, so the same options value can be handed to any encoder. Every field’s default leaves a format’s output as it was before the field existed.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.quality: u8Lossy quality, 1–100. Ignored by lossless formats, and by a format
with both modes when lossless is set.
lossless: boolFor a format that has both a lossy and a lossless mode (WebP), choose
lossless. Off by default: such a format encodes lossy at quality,
as cwebp and sharp do. Formats with one mode ignore it.
effort: Option<u8>CPU spent for a smaller file, 0 (fastest) to 10, in each format’s
own range as sharp defines it: WebP 0–6 and AVIF 0–9, both with a
default of 4. None is the format’s default.
compression_level: Option<u8>PNG’s DEFLATE level, 0 (store) to 9. None derives it from
quality, as before this option existed.
palette: boolWrite PNG as a palette image of at most colours entries (sharp’s
palette). Setting colours or dither implies it, as in sharp.
colours: Option<u16>The palette size for palette PNG and GIF, 2–256. None is 256 for
PNG, and for GIF the size quality implies.
dither: Option<f32>How much of the quantization error a palette image diffuses, 0 (none)
to 1 (full Floyd-Steinberg, the default). None is 1.
alpha_quality: u8Quality of lossy WebP’s alpha channel, 0–100; 100, the default, keeps it lossless.
near_lossless: boolLossless WebP that may change pixels a little where it saves bytes,
by as much as quality allows (sharp’s nearLossless; 100 changes
nothing). Implies lossless.
chroma_subsampling: Option<ChromaSubsampling>Chroma sampling for JPEG and AVIF. None is each format’s default:
for JPEG 4:2:0 below quality 90 and 4:4:4 from it, for AVIF 4:2:0.
keep_exif: boolCopy the source’s EXIF block into the output (sharp’s keepExif),
where the format has a place for one: JPEG, PNG, WebP and AVIF. Off
by default, which strips camera data and location from uploads.
keep_xmp: boolCopy the source’s XMP packet into the output (sharp’s keepXmp),
where the format has a place for one: JPEG, PNG, WebP, TIFF, AVIF
and JPEG XL. Off by default, as for EXIF.
progressive: boolWrite JPEG as progressive (sharp’s progressive): a coarse picture
first, sharpened by later scans, and usually a little smaller. The
encoder then holds the image’s coefficients rather than streaming.
Implementations§
Source§impl EncodeOptions
impl EncodeOptions
Sourcepub const DEFAULT_QUALITY: u8 = 80
pub const DEFAULT_QUALITY: u8 = 80
The default quality used when none is given.
Sourcepub fn with_quality(quality: u8) -> Result<EncodeOptions, PixelsError>
pub fn with_quality(quality: u8) -> Result<EncodeOptions, PixelsError>
Options with the given quality.
§Errors
Returns PixelsError::InvalidArgument unless quality is in 1..=100.
Sourcepub const fn with_lossless(self, lossless: bool) -> EncodeOptions
pub const fn with_lossless(self, lossless: bool) -> EncodeOptions
These options with lossless replaced.
Sourcepub fn with_effort(self, effort: u8) -> Result<EncodeOptions, PixelsError>
pub fn with_effort(self, effort: u8) -> Result<EncodeOptions, PixelsError>
These options with an encoding effort, 0..=10 (see
EncodeOptions::effort). A value past a format’s own range is
clamped to it.
§Errors
Returns PixelsError::InvalidArgument above 10.
Sourcepub fn with_compression_level(
self,
level: u8,
) -> Result<EncodeOptions, PixelsError>
pub fn with_compression_level( self, level: u8, ) -> Result<EncodeOptions, PixelsError>
These options with a PNG DEFLATE level, 0..=9.
§Errors
Returns PixelsError::InvalidArgument above 9.
Sourcepub const fn with_palette(self, palette: bool) -> EncodeOptions
pub const fn with_palette(self, palette: bool) -> EncodeOptions
These options with palette PNG on or off.
Sourcepub fn with_colours(self, colours: u16) -> Result<EncodeOptions, PixelsError>
pub fn with_colours(self, colours: u16) -> Result<EncodeOptions, PixelsError>
These options with a palette size, 2..=256, which for PNG implies a palette.
§Errors
Returns PixelsError::InvalidArgument outside 2..=256.
Sourcepub fn with_dither(self, dither: f32) -> Result<EncodeOptions, PixelsError>
pub fn with_dither(self, dither: f32) -> Result<EncodeOptions, PixelsError>
These options with a dithering level, 0..=1, which for PNG implies a palette.
§Errors
Returns PixelsError::InvalidArgument outside 0..=1.
Sourcepub fn with_alpha_quality(
self,
quality: u8,
) -> Result<EncodeOptions, PixelsError>
pub fn with_alpha_quality( self, quality: u8, ) -> Result<EncodeOptions, PixelsError>
These options with a lossy WebP alpha quality, 0..=100.
§Errors
Returns PixelsError::InvalidArgument above 100.
Sourcepub const fn with_near_lossless(self, near_lossless: bool) -> EncodeOptions
pub const fn with_near_lossless(self, near_lossless: bool) -> EncodeOptions
These options with near-lossless WebP on or off.
Sourcepub const fn with_chroma_subsampling(
self,
subsampling: ChromaSubsampling,
) -> EncodeOptions
pub const fn with_chroma_subsampling( self, subsampling: ChromaSubsampling, ) -> EncodeOptions
These options with an explicit chroma subsampling.
Sourcepub const fn with_keep_exif(self, keep: bool) -> EncodeOptions
pub const fn with_keep_exif(self, keep: bool) -> EncodeOptions
These options keeping the source’s EXIF, or not.
Sourcepub const fn with_keep_xmp(self, keep: bool) -> EncodeOptions
pub const fn with_keep_xmp(self, keep: bool) -> EncodeOptions
These options with keep_xmp replaced.
Sourcepub const fn with_keep_metadata(self, keep: bool) -> EncodeOptions
pub const fn with_keep_metadata(self, keep: bool) -> EncodeOptions
These options keeping EXIF and XMP both (sharp’s keepMetadata;
the ICC profile is always kept).
Sourcepub const fn with_progressive(self, progressive: bool) -> EncodeOptions
pub const fn with_progressive(self, progressive: bool) -> EncodeOptions
These options with progressive JPEG on or off.
Sourcepub const fn wants_palette(&self) -> bool
pub const fn wants_palette(&self) -> bool
Whether a PNG should be written as a palette image.
Trait Implementations§
Source§impl Clone for EncodeOptions
impl Clone for EncodeOptions
Source§fn clone(&self) -> EncodeOptions
fn clone(&self) -> EncodeOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more