#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ImageOptions {
pub image_size: f64,
pub hide_background_dots: bool,
pub margin: u32,
pub cross_origin: Option<String>,
pub save_as_blob: bool,
}
impl Default for ImageOptions {
fn default() -> Self {
Self {
image_size: 0.4,
hide_background_dots: true,
margin: 0,
cross_origin: None,
save_as_blob: true,
}
}
}
impl ImageOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_image_size(mut self, size: f64) -> Self {
self.image_size = size.clamp(0.0, 1.0);
self
}
pub fn with_hide_background_dots(mut self, hide: bool) -> Self {
self.hide_background_dots = hide;
self
}
pub fn with_margin(mut self, margin: u32) -> Self {
self.margin = margin;
self
}
pub fn with_cross_origin(mut self, cross_origin: impl Into<String>) -> Self {
self.cross_origin = Some(cross_origin.into());
self
}
pub fn with_save_as_blob(mut self, save: bool) -> Self {
self.save_as_blob = save;
self
}
}