Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -240,9 +243,6 @@ image = { version = "0.25.6", default-features = false, features = [
# up here.
"png",
"jpeg",
"gif",
"webp",
"tiff",
# "bmp",
# "ico",
# "avif",
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/settings/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 15 additions & 3 deletions sdk/src/utils/thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ impl TryFrom<ImageFormat> 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(),
Expand All @@ -65,8 +68,11 @@ impl From<ThumbnailFormat> 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,
}
}
Expand All @@ -77,8 +83,11 @@ impl From<ThumbnailFormat> 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())
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())?,
}

Expand Down