11/23
No files matched your search
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 5.4 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 2.5 MiB |
|
After Width: | Height: | Size: 7.7 MiB |
@@ -0,0 +1,43 @@
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
|
||||
# Everforest dark hard palette (you can adjust for soft/medium/light variants)
|
||||
EVERFOREST_PALETTE = [
|
||||
(235, 219, 178), # fg
|
||||
(54, 61, 64), # bg0
|
||||
(49, 56, 59), # bg1
|
||||
(39, 46, 49), # bg2
|
||||
(69, 133, 136), # aqua
|
||||
(204, 36, 29), # red
|
||||
(152, 151, 26), # yellow
|
||||
(184, 187, 38), # green
|
||||
(215, 153, 33), # orange
|
||||
(177, 98, 134), # purple
|
||||
(104, 157, 106), # dark green
|
||||
(142, 192, 124), # light green
|
||||
]
|
||||
|
||||
|
||||
def closest_color(rgb, palette):
|
||||
"""Find closest color in palette to given rgb."""
|
||||
r, g, b = rgb
|
||||
distances = [np.sqrt((r-pr)**2 + (g-pg)**2 + (b-pb)**2) for pr, pg, pb in palette]
|
||||
return palette[int(np.argmin(distances))]
|
||||
|
||||
|
||||
def everforestify_image(input_path: str, output_path: str):
|
||||
img = Image.open(input_path).convert("RGB")
|
||||
pixels = np.array(img)
|
||||
|
||||
# Vectorized mapping
|
||||
flat_pixels = pixels.reshape(-1, 3)
|
||||
mapped_pixels = np.array([closest_color(tuple(p), EVERFOREST_PALETTE) for p in flat_pixels])
|
||||
new_pixels = mapped_pixels.reshape(pixels.shape).astype(np.uint8)
|
||||
|
||||
new_img = Image.fromarray(new_pixels, "RGB")
|
||||
new_img.save(output_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example usage
|
||||
everforestify_image("gothic2.jpg", "everforest_gothic2.jpg")
|
||||
|
After Width: | Height: | Size: 3.2 MiB |
|
After Width: | Height: | Size: 349 KiB |
|
After Width: | Height: | Size: 350 KiB |
|
After Width: | Height: | Size: 5.3 MiB |
|
After Width: | Height: | Size: 4.6 MiB |
|
After Width: | Height: | Size: 2.7 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 117 KiB |