feat(manganis): add with_width/with_height for auto aspect-ratio image sizing#5606
Open
theonlyhennygod wants to merge 1 commit into
Open
feat(manganis): add with_width/with_height for auto aspect-ratio image sizing#5606theonlyhennygod wants to merge 1 commit into
theonlyhennygod wants to merge 1 commit into
Conversation
…e sizing Add WidthOnly and HeightOnly variants to ImageSize enum, enabling users to specify only one dimension and have the other derived from the image's aspect ratio at build time. Closes DioxusLabs#5458
ealmloff
requested changes
Jun 2, 2026
ealmloff
left a comment
Member
There was a problem hiding this comment.
Thanks! Adding an enum variant is the right change for a non-breaking release, but since we have already cut over to 0.8 alphas, we can simplify this api
| height: u32, | ||
| }, | ||
| /// Only the width is specified; the height will be derived from the image's aspect ratio | ||
| WidthOnly { |
Member
There was a problem hiding this comment.
Since we now support any combination, the struct can be width: Option, height: Option now with methods to create different variants
| if let Ok(image) = &mut image { | ||
| if let ImageSize::Manual { width, height } = image_options.size() { | ||
| *image = image.resize_exact(width, height, image::imageops::FilterType::Lanczos3); | ||
| match image_options.size() { |
Member
There was a problem hiding this comment.
changing to optional fields simplifies this logic to manual_dim.unwrap_or_else(existing_dim)
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #5458
Adds the ability to specify only one dimension (
with_widthorwith_height) when resizing image assets, and have the other dimension automatically derived from the image's aspect ratio at build time.Changes
packages/manganis/manganis-core/src/images.rsImageSize::WidthOnly { width }andImageSize::HeightOnly { height }variants to theImageSizeenumwith_width(width: u32)andwith_height(height: u32)constmethods toAssetOptionsBuilder<ImageAssetOptions>packages/cli/src/opt/image.rsprocess_imageto handle the newImageSizevariants by reading the decoded image's actual dimensions and computing the missing dimension from the aspect ratioUsage
Implementation Notes
dxrunsresize_exact(same asManual) for consistencyImageSizevariants are#[repr(C, u8)]compatible with the existing serialization infrastructureconst fnto match the existing API convention