mirror of
https://github.com/arabianq/colorgram-rust.git
synced 2026-04-27 22:21:22 +00:00
colorgram::extract now accepts &[u8] instead of Path
This commit is contained in:
+2
-6
@@ -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
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user