Open
Conversation
Contributor
|
Hello, any particular reason this PR cannot be merged? |
Collaborator
It hasn't passed CI and typically won't be reviewed until it does. I do think though that we don't want to deprecate the |
Collaborator
I agree, |
Contributor
|
@panekj then how about this: pub fn img(image: impl Fn() -> Vec<u8> + 'static) -> Img {
let image = image::load_from_memory(&image()).ok();
let width = image.as_ref().map_or(0, |img| img.width());
let height = image.as_ref().map_or(0, |img| img.height());
let data = Arc::new(image.map_or(Default::default(), |img| img.into_rgba8().into_vec()));
let blob = Blob::new(data);
let image = peniko::Image::new(blob, peniko::Format::Rgba8, width, height);
img_dynamic(move || image.clone())
}
pub fn img_from_path(image: impl Fn() -> PathBuf + 'static) -> Img {
let image = image::open(&image()).ok();
let width = image.as_ref().map_or(0, |img| img.width());
let height = image.as_ref().map_or(0, |img| img.height());
let data = Arc::new(image.map_or(Default::default(), |img| img.into_rgba8().into_vec()));
let blob = Blob::new(data);
let image = peniko::Image::new(blob, peniko::Format::Rgba8, width, height);
img_dynamic(move || image.clone())
}
pub fn img_from_image(image: impl Fn() -> peniko::Image + 'static) -> Img {
img_dynamic(move || image())
} |
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.
While working with the
imgAPI I was frustrated to find that I had to create a vector of u8's even though I already had either a DynamicImage instance or PathBuf instance. e.g. when creating a new file (DynamicImage) or opening a file (PathBuf).I also noted that
img_dynamicvisibility ispub(crate)which meant I could not use that either.This PR adds three well-named methods (commit 1) and deprecates the old one (commit 2).
See commits/changes.