diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index e355a69ab..7d2868a13 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -29,7 +29,10 @@ rustdoc-args = ["--cfg", "docsrs"] [features] default = ["openssl", "default_http"] -add_thumbnails = ["image"] +add_thumbnails = ["dep:image"] +image_gif = ["add_thumbnails", "image/gif"] +image_webp = ["add_thumbnails", "image/webp"] +image_tiff = ["add_thumbnails", "image/tiff"] file_io = [] fetch_remote_manifests = ["dep:wasi"] json_schema = ["dep:schemars"] @@ -240,9 +243,6 @@ image = { version = "0.25.6", default-features = false, features = [ # up here. "png", "jpeg", - "gif", - "webp", - "tiff", # "bmp", # "ico", # "avif", diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 367704d9a..a454a43a9 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -160,9 +160,12 @@ //! If both are enabled, `rust_native_crypto` is used. //! //! Other features: -//! - **add_thumbnails**: Adds the [`image`](https://github.com/image-rs/image) crate to enable auto-generated thumbnails, if possible and enabled in settings. +//! - **add_thumbnails**: Adds the [`image`](https://github.com/image-rs/image) crate to enable auto-generated thumbnails (PNG/JPEG), if possible and enabled in settings. //! - **fetch_remote_manifests**: Fetches remote manifests over the network when no embedded manifest is present and that option is enabled in settings. //! - **file_io**: Enables APIs that use filesystem I/O. +//! - **image_gif**: Enables GIF thumbnail support (requires `add_thumbnails`). +//! - **image_tiff**: Enables TIFF thumbnail support (requires `add_thumbnails`). +//! - **image_webp**: Enables WebP thumbnail support (requires `add_thumbnails`). //! - **json_schema**: Adds the [`schemars`](https://github.com/GREsau/schemars) crate to derive JSON schemas for JSON-compatible structs. //! - **pdf**: Enables basic PDF read support. //! - **rust_native_crypto**: Use Rust native cryptography. diff --git a/sdk/src/settings/builder.rs b/sdk/src/settings/builder.rs index ce95948e2..847449a4c 100644 --- a/sdk/src/settings/builder.rs +++ b/sdk/src/settings/builder.rs @@ -43,10 +43,13 @@ pub enum ThumbnailFormat { /// An image in JPEG format. Jpeg, /// An image in GIF format. + #[cfg(feature = "image_gif")] Gif, /// An image in WEBP format. + #[cfg(feature = "image_webp")] WebP, /// An image in TIFF format. + #[cfg(feature = "image_tiff")] Tiff, } /// Quality of the thumbnail. diff --git a/sdk/src/utils/thumbnail.rs b/sdk/src/utils/thumbnail.rs index 7f19d1df0..efc05ebd1 100644 --- a/sdk/src/utils/thumbnail.rs +++ b/sdk/src/utils/thumbnail.rs @@ -50,8 +50,11 @@ impl TryFrom for ThumbnailFormat { match format { ImageFormat::Png => Ok(ThumbnailFormat::Png), ImageFormat::Jpeg => Ok(ThumbnailFormat::Jpeg), + #[cfg(feature = "image_gif")] ImageFormat::Gif => Ok(ThumbnailFormat::Gif), + #[cfg(feature = "image_webp")] ImageFormat::WebP => Ok(ThumbnailFormat::WebP), + #[cfg(feature = "image_tiff")] ImageFormat::Tiff => Ok(ThumbnailFormat::Tiff), _ => Err(Error::UnsupportedThumbnailFormat( format.to_mime_type().to_owned(), @@ -65,8 +68,11 @@ impl From for ImageFormat { match format { ThumbnailFormat::Png => ImageFormat::Png, ThumbnailFormat::Jpeg => ImageFormat::Jpeg, + #[cfg(feature = "image_gif")] ThumbnailFormat::Gif => ImageFormat::Gif, + #[cfg(feature = "image_webp")] ThumbnailFormat::WebP => ImageFormat::WebP, + #[cfg(feature = "image_tiff")] ThumbnailFormat::Tiff => ImageFormat::Tiff, } } @@ -77,8 +83,11 @@ impl From for config::ValueKind { let variant = match value { ThumbnailFormat::Png => "png", ThumbnailFormat::Jpeg => "jpeg", + #[cfg(feature = "image_gif")] ThumbnailFormat::Gif => "gif", + #[cfg(feature = "image_webp")] ThumbnailFormat::WebP => "webp", + #[cfg(feature = "image_tiff")] ThumbnailFormat::Tiff => "tiff", }; config::ValueKind::String(variant.to_owned()) @@ -158,9 +167,11 @@ where match prefer_smallest_format { true => match input_format { // TODO: investigate more formats - ThumbnailFormat::Png | ThumbnailFormat::Tiff - if !image.color().has_alpha() => - { + ThumbnailFormat::Png if !image.color().has_alpha() => { + ThumbnailFormat::Jpeg + } + #[cfg(feature = "image_tiff")] + ThumbnailFormat::Tiff if !image.color().has_alpha() => { ThumbnailFormat::Jpeg } _ => input_format, @@ -206,6 +217,7 @@ where FilterType::default(), ))?, }, + #[cfg(any(feature = "image_gif", feature = "image_webp", feature = "image_tiff"))] _ => image.write_to(output, output_format.into())?, }