summaryrefslogtreecommitdiff
path: root/src/picture.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-07-26 12:33:35 +0200
committerJulian T <julian@jtle.dk>2021-07-26 12:33:35 +0200
commit0ddf24fa0be620fc10cc07247b2c738b32943042 (patch)
tree7bf46891e4da4a9aa1b46417c33072fb9a0e6e57 /src/picture.rs
parentc3c69b160f4c5fd851fd1a49c01f633a56351f5d (diff)
Added rendering of simple template
Diffstat (limited to 'src/picture.rs')
-rw-r--r--src/picture.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/picture.rs b/src/picture.rs
index f92876c..76a33df 100644
--- a/src/picture.rs
+++ b/src/picture.rs
@@ -5,6 +5,7 @@ use std::io::{Read, Seek};
use image::io::Reader as ImageReader;
use image::error::ImageError;
use image::imageops;
+use serde::Serialize;
use crate::context::Context;
@@ -20,11 +21,11 @@ pub enum ConversionError {
ImageError(ImageError),
}
-#[derive(Debug)]
+#[derive(Debug, Serialize)]
pub struct Picture {
- taken: Option<String>,
- hash: md5::Digest,
- path: PathBuf,
+ pub taken: Option<String>,
+ hash: String,
+ pub path: PathBuf,
}
pub struct Converter<'a> {
@@ -32,7 +33,7 @@ pub struct Converter<'a> {
pic: &'a Picture,
}
-fn hash_reader<R: Read>(reader: &mut R) -> Result<md5::Digest, io::Error> {
+fn hash_reader<R: Read>(reader: &mut R) -> Result<String, io::Error> {
let mut hash = md5::Context::new();
let mut buff = [0; 1024];
@@ -46,7 +47,7 @@ fn hash_reader<R: Read>(reader: &mut R) -> Result<md5::Digest, io::Error> {
hash.consume(&buff[..count])
}
- Ok(hash.compute())
+ Ok(format!("{:?}", hash.compute()))
}
impl Picture {
@@ -106,7 +107,7 @@ impl Converter<'_> {
}
pub fn get_size(&mut self, ctx: &Context, size: u32) -> Result<PathBuf, ImageError> {
- let hash = md5::compute(format!("{},{},{:?}", size, ctx.options.ext, self.pic.hash));
+ let hash = md5::compute(format!("{},{},{}", size, ctx.options.ext, self.pic.hash));
let name = format!("{:?}.{}", hash, ctx.options.ext);
let path = ctx.imgdir.join(name);