From 0ddf24fa0be620fc10cc07247b2c738b32943042 Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 26 Jul 2021 12:33:35 +0200 Subject: Added rendering of simple template --- src/picture.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/picture.rs') 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, - hash: md5::Digest, - path: PathBuf, + pub taken: Option, + hash: String, + pub path: PathBuf, } pub struct Converter<'a> { @@ -32,7 +33,7 @@ pub struct Converter<'a> { pic: &'a Picture, } -fn hash_reader(reader: &mut R) -> Result { +fn hash_reader(reader: &mut R) -> Result { let mut hash = md5::Context::new(); let mut buff = [0; 1024]; @@ -46,7 +47,7 @@ fn hash_reader(reader: &mut R) -> Result { 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 { - 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); -- cgit v1.2.3