Skip to content

Commit

Permalink
ad
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed May 20, 2024
1 parent a09dd48 commit fdc4cf4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modern_colorthief.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
__version__: str

def get_color(
location: str,
image: str,
quality: int | None = 10,
) -> tuple[int, int, int]: ...
def get_palette(
location: str,
image: str,
color_count: int | None = 10,
quality: int | None = 10,
) -> list[tuple[int, int, int]]: ...
Empty file added src/python/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions src/lib.rs → src/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ fn get_image_buffer(img: image::DynamicImage) -> (Vec<u8>, ColorFormat) {
/// Returns the pallette given an image
#[pyfunction]
fn get_palette(
location: String,
image: String,
color_count: Option<u8>,
quality: Option<u8>,
) -> PyResult<Vec<(u8, u8, u8)>> {
let img = image::open(&std::path::Path::new(&location)).unwrap();
let img = image::open(&std::path::Path::new(&image)).unwrap();
let (buffer, color_type) = get_image_buffer(img);

let colors = color_thief::get_palette(
Expand All @@ -39,8 +39,8 @@ fn get_palette(

// Gets the dominant color given an image
#[pyfunction]
fn get_color(location: String, quality: Option<u8>) -> PyResult<(u8, u8, u8)> {
let palette = get_palette(location, Some(5), Some(quality.unwrap_or(10))).unwrap();
fn get_color(image: String, quality: Option<u8>) -> PyResult<(u8, u8, u8)> {
let palette = get_palette(image, Some(5), Some(quality.unwrap_or(10))).unwrap();
Ok(palette[0])
}

Expand Down
Binary file added test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import io
from PIL import Image

img = Image.open('test.jpg', mode='r')

img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()

print(img_byte_arr)

0 comments on commit fdc4cf4

Please sign in to comment.