json2pdf_client/protocol/elements/
image.rs1use serde::Serialize;
2use crate::protocol::elements::Element;
3
4#[derive(Debug, Clone, Serialize)]
6pub struct Image {
7 data: String,
8 height: f32,
9 width: f32,
10}
11
12impl Image {
13 pub fn new_base64(data: String, height: f32, width: f32) -> Self {
15 Self {
16 data,
17 height,
18 width,
19 }
20 }
21
22 pub fn new_bytes(data: &[u8], height: f32, width: f32) -> Self {
24 Self {
25 data: base64::encode(data),
26 height,
27 width,
28 }
29 }
30}
31
32#[allow(clippy::from_over_into)]
33impl Into<Element> for Image {
34 fn into(self) -> Element {
35 Element::image(self)
36 }
37}