From 654a35bc1d232a944b066cc3492daf589a8ba83a Mon Sep 17 00:00:00 2001 From: arabian Date: Tue, 6 Jan 2026 05:17:23 +0300 Subject: [PATCH] colorgram::extract now accepts &[u8] instead of Path --- src/lib.rs | 8 ++------ src/main.rs | 5 ++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5f55aef..14f2912 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ use image; use std::{ error::Error, fmt::{Display, Formatter, Result as fmtResult}, - path::Path, }; pub struct Hsl { @@ -78,11 +77,8 @@ fn rgb_to_hsl(rgb: &Rgb) -> Hsl { Hsl { h, s, l: l as u8 } } -pub fn extract>( - path: P, - number_of_color: usize, -) -> Result, Box> { - let img = image::open(path)?; +pub fn extract(buffer: &[u8], number_of_color: usize) -> Result, Box> { + let img = image::load_from_memory(buffer)?; let img = img.to_rgb8(); let mut samples = vec![0u32; 4 * 4096]; diff --git a/src/main.rs b/src/main.rs index 39f2c89..4c687d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,10 @@ fn main() { assert!(input_path.is_file(), "Input path is not a file"); assert!(colors_amount > 0, "Colors amount must be greater than zero"); - match extract(input_path, colors_amount) { + let img = image::open(input_path).unwrap(); + let buf = img.as_bytes(); + + match extract(buf, colors_amount) { Ok(colors) => { for color in colors { let style = Style::new()