colorgram::extract now accepts &[u8] instead of Path

This commit is contained in:
2026-01-06 05:17:23 +03:00
parent 3dfdf0a91f
commit 654a35bc1d
2 changed files with 6 additions and 7 deletions
+2 -6
View File
@@ -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<P: AsRef<Path>>(
path: P,
number_of_color: usize,
) -> Result<Vec<Color>, Box<dyn Error>> {
let img = image::open(path)?;
pub fn extract(buffer: &[u8], number_of_color: usize) -> Result<Vec<Color>, Box<dyn Error>> {
let img = image::load_from_memory(buffer)?;
let img = img.to_rgb8();
let mut samples = vec![0u32; 4 * 4096];
+4 -1
View File
@@ -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()