DioxusLabs / DioxusLabs/dioxus

Ability to serve unmodified image assets

Open
#4,625 1 comment 1 reaction 0 assignees View on GitHub
enhancement manganis
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

## Feature Request
I have some webp images that I manually tweaked the quality level when creating the image to be exactly where I want it, when I use these with the asset macro like this `asset!("/assets/my_image")`, the image served up is much larger than the original, sometimes more than double. I looked at ImageAssetOptions, but I only see options for what format to use, nothing about compression options.

## Implement Suggestion

I tried using [`ImageFormat::Unknown`](https://docs.rs/dioxus/0.7.0-rc.0/dioxus/prelude/enum.ImageFormat.html#variant.Unknown) but that still results in the larger image being served. It's possible that this is a bug, since the comment [here](https://github.com/DioxusLabs/dioxus/blob/80731da25a698b655b1679e2e9deaa2959740d58/packages/cli-opt/src/image/mod.rs#L53) suggests maybe it should work, but the pattern above it will match unknown image formats that didn't fail to load causing it to still recreate the file. ImageFormat::Unknown also doesn't really convey the intent as the image format is known and that mismatch may cause pain later (e.g. idk what mime type unknown will be served with) so I wonder if we should have a more intentional API for this.

Perhaps something like
```rust
asset!("/assets/my_image.webp", ImageAssetOptions::new().with_original();
```

It would also be nice to be able to control the quality of formats that support it, maybe thinking about how that should work would provide a more future proof API.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.