From fb8c852a4dc0d1e87f66de90bb076d9f115f6e4a Mon Sep 17 00:00:00 2001 From: zeefaad Date: Sun, 8 Mar 2026 15:31:55 +0100 Subject: [PATCH] png to jpg for space --- rklipd/src/database.rs | 11 ++++++++--- rklipd/src/models.rs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) 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> {