diff --git a/rklipd/src/database.rs b/rklipd/src/database.rs index 5e97ba8..3b79d75 100644 --- a/rklipd/src/database.rs +++ b/rklipd/src/database.rs @@ -1,4 +1,5 @@ use crate::models::{ClipboardData, ClipboardEntry, Image}; +use image::codecs::jpeg::JpegEncoder; use image::codecs::png::PngEncoder; use image::{ExtendedColorType, ImageEncoder}; use rusqlite::Connection; @@ -49,12 +50,16 @@ impl Database { let img_path = img.file_path(&self.dir_path); let file = fs::File::create(&img_path)?; - let encoder = PngEncoder::new(file); + let rgb_pixels: Vec = raw_pixels + .chunks_exact(4) + .flat_map(|rgba| [rgba[0], rgba[1], rgba[2]]) + .collect(); + let encoder = JpegEncoder::new_with_quality(file, 70); encoder.write_image( - raw_pixels, + &rgb_pixels, img.width, img.height, - ExtendedColorType::Rgba8, + ExtendedColorType::Rgb8, )?; } ("image", img.id.to_string()) diff --git a/rklipd/src/models.rs b/rklipd/src/models.rs index bbfa4d0..c06e0ad 100644 --- a/rklipd/src/models.rs +++ b/rklipd/src/models.rs @@ -27,7 +27,7 @@ impl Image { pub fn file_path(&self, base_dir: &str) -> PathBuf { std::path::Path::new(base_dir) .join("images") - .join(format!("{}.png", self.id)) + .join(format!("{}.jpg", self.id)) } pub fn load_bytes(&self, dir_path: &str) -> io::Result> {