summaryrefslogtreecommitdiff
path: root/dichroism/src/models/photo_set.rs
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-10-31 10:14:31 -0400
committerAdam T. Carpenter <atc@53hor.net>2020-10-31 10:14:31 -0400
commit3e1eadbbfdca1b2c0cb32ba4c8e1160a60e0ccb8 (patch)
tree3b712bc31a6db0a16ddfd4a02529d8b2497a5c54 /dichroism/src/models/photo_set.rs
parent00c71f6baff136a88805ca2e3f9ef72453ac9f35 (diff)
downloadtheglassyladies-3e1eadbbfdca1b2c0cb32ba4c8e1160a60e0ccb8.tar.xz
theglassyladies-3e1eadbbfdca1b2c0cb32ba4c8e1160a60e0ccb8.zip
All basic functionality implemented.
Diffstat (limited to 'dichroism/src/models/photo_set.rs')
-rw-r--r--dichroism/src/models/photo_set.rs57
1 files changed, 3 insertions, 54 deletions
diff --git a/dichroism/src/models/photo_set.rs b/dichroism/src/models/photo_set.rs
index 7187c65..f2c7677 100644
--- a/dichroism/src/models/photo_set.rs
+++ b/dichroism/src/models/photo_set.rs
@@ -1,61 +1,10 @@
-use super::photo::Photo;
-use crate::constants::{PHOTO_BASE_XY, PHOTO_FULLSIZE_XY, PHOTO_THUMBNAIL_XY};
-use crate::error::DichroismError;
-use crate::result::Result;
-use base64::decode;
-use image::imageops::FilterType;
-use image::GenericImageView;
-use once_cell::sync::Lazy;
-use regex::Regex;
-
-static DATA_URI_RE: Lazy<Regex> = Lazy::new(|| {
- Regex::new("^data:image/(png|jpeg);base64,(?P<data>.+)")
- .expect("Couldn't parse data URI Regex.")
-});
+use super::Photo;
+#[derive(Debug, Clone)]
pub struct PhotoSet {
+ pub id: Option<i32>,
pub original: Photo, // original, just for safe-keeping
pub fullsize: Photo, // full-size, "zoomed" view
pub base: Photo, // basic viewing
pub thumbnail: Photo, // tiny, square thumbnail
}
-
-impl PhotoSet {
- pub fn from_photos(original: Photo, fullsize: Photo, base: Photo, thumbnail: Photo) -> Self {
- Self {
- original,
- fullsize,
- base,
- thumbnail,
- }
- }
-
- pub fn from_data_uri(uri: &str) -> Result<Self> {
- let data = DATA_URI_RE
- .captures(uri)
- .ok_or(DichroismError::UriDataExtract)?
- .name("data")
- .ok_or(DichroismError::UriDataExtract)?
- .as_str();
- let original = image::load_from_memory(&decode(data)?)?;
- let fullsize = original.resize(PHOTO_FULLSIZE_XY, PHOTO_FULLSIZE_XY, FilterType::Lanczos3);
- let base = original.resize(PHOTO_BASE_XY, PHOTO_BASE_XY, FilterType::Lanczos3);
-
- let (width, height) = original.dimensions();
- let thumbnail = if width > height {
- let offset = (width - height) / 2;
- original.crop_imm(offset, 0, width - offset * 2, height)
- } else {
- let offset = (height - width) / 2;
- original.crop_imm(0, offset, width, height - offset * 2)
- }
- .resize(PHOTO_THUMBNAIL_XY, PHOTO_THUMBNAIL_XY, FilterType::Lanczos3);
-
- Ok(Self {
- original: Photo::from_image(&original)?,
- fullsize: Photo::from_image(&fullsize)?,
- base: Photo::from_image(&base)?,
- thumbnail: Photo::from_image(&thumbnail)?,
- })
- }
-}