Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed May 20, 2024
1 parent f67e076 commit a0dbec4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from python.modern_colorthief.modern_colorthief import get_color, get_palette
from modern_colorthief import get_color, get_palette
from colorthief import ColorThief
from pathlib import Path
import os
Expand Down
2 changes: 1 addition & 1 deletion examples/test_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from python.modern_colorthief.modern_colorthief import get_color, get_palette
from modern_colorthief import get_color, get_palette
from fast_colorthief import get_dominant_color, get_palette as f_get_palette
import timeit
from colorthief import ColorThief
Expand Down
2 changes: 1 addition & 1 deletion src/python/modern_colorthief/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_palette(
quality: int | None = 10,
) -> list[tuple[int, int, int]]:
if isinstance(image, str):
return _get_palette_given_string(image, color_count, quality)
return _get_palette_given_location(image, color_count, quality)

if isinstance(image, bytes):
return _get_palette_given_bytes(image, color_count, quality)
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.
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
import modern_colorthief


x = modern_colorthief.get_color(img_byte_arr)
x = modern_colorthief.get_palette(img_byte_arr)

print(isinstance(img_byte_arr, io.BytesIO))
print(x)
39 changes: 36 additions & 3 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,38 @@

path = os.path.join(BASE_DIR, "test.jpg")

TARGET_PALTTE = [
(31, 169, 167),
(179, 51, 55),
(219, 176, 127),
(248, 233, 225),
(160, 98, 87),
(63, 47, 43),
(132, 162, 107),
(179, 119, 52),
(237, 220, 155),
]
TARGET_COLOR = (201, 160, 118)


def test_path():
dominant_color = modern_colorthief.get_color(path)
dominant_palette = modern_colorthief.get_palette(path)

assert dominant_color == TARGET_COLOR

assert dominant_color == (201, 160, 118)
# If we do not use PILLOW the image output is slightly different
assert dominant_palette == [
(30, 169, 166),
(179, 51, 55),
(219, 176, 127),
(248, 233, 225),
(160, 98, 87),
(63, 47, 42),
(131, 163, 107),
(179, 119, 52),
(237, 220, 155),
]


def test_bytesio():
Expand All @@ -22,7 +49,10 @@ def test_bytesio():
img.save(img_byte_arr, format="PNG")

dominant_color = modern_colorthief.get_color(img_byte_arr)
assert dominant_color == (201, 160, 118)
dominant_palette = modern_colorthief.get_palette(img_byte_arr)

assert dominant_color == TARGET_COLOR
assert dominant_palette == TARGET_PALTTE


def test_bytes():
Expand All @@ -32,4 +62,7 @@ def test_bytes():
img.save(img_byte_arr, format="PNG")

dominant_color = modern_colorthief.get_color(img_byte_arr.getvalue())
assert dominant_color == (201, 160, 118)
dominant_palette = modern_colorthief.get_palette(img_byte_arr.getvalue())

assert dominant_color == TARGET_COLOR
assert dominant_palette == TARGET_PALTTE
7 changes: 7 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import modern_colorthief


def test_version():
version = modern_colorthief.__version__

assert isinstance(version, str)

0 comments on commit a0dbec4

Please sign in to comment.