Use Image from Memoryin html! macro #1984
Answered
by
teymour-aldridge
d-mceneaney
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi!
I imagine that this might be achievable using
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs>
(by converting the image into the needed format, and concatenating as
needed).
I suspect that you might have an easier time using the browser's native
APIs for image processing (using https://docs.rs/web-sys
<https://docs.rs/web-sys>) instead of the Rust `image` crate (one of the
crate authors suggests this
image-rs/image#1496 (comment)
<image-rs/image#1496 (comment)>)
because they are likely to be more efficient because they have access to
hardware functions that WebAssembly modules don't. Opening an image from
the local filesystem is also going to be tricky (not least because it
may not exist on other people's computers), so you'd either want to
bundle this image into your binary (with the builtin `include_bytes!`
macro) or host it somewhere and then load it.
Apologies for this bundle of negativity, and if I've misinterpreted
anything in your question.
…On 02/08/2021 17:18, d-mceneaney wrote:
Hi,
I would like to use the image crate to load or manipulate images from
memory. Is there a way to use image::DynamicImage within the html!
macro? I received the error below about the IntoPropValue trait not
being implemented for DynamicImage. Is there an idiomatic way to code
this or some way to derive the trait?
Thanks.
//load and image
let graph= image::open("graph.png").unwrap();
....
html! {
<img id= "graph" src=graph alt="graph"/>
}
....
Error:
error[E0277]: the trait bound |DynamicImage:
IntoPropValue<Option<Cow<'static, str>>>| is not satisfied
graph <graph>
^^^^^ the trait `IntoPropValue>>` is not implemented for `DynamicImage`
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1984>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKFSTPOB3PANDFSWWCIBBA3T23ANXANCNFSM5BNB25JA>.
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
d-mceneaney
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I would like to use the image crate to load or manipulate images from memory. Is there a way to use image::DynamicImage within the html! macro? I received the error below about the IntoPropValue trait not being implemented for DynamicImage. Is there an idiomatic way to code this or some way to derive the trait?
Thanks.
Error:
error[E0277]: the trait bound
DynamicImage: IntoPropValue<Option<Cow<'static, str>>>
is not satisfied^^^^^ the trait `IntoPropValue>>` is not implemented for `DynamicImage`
Beta Was this translation helpful? Give feedback.
All reactions