Skip to content

Commit 584ff08

Browse files
committed
Update Color_Palette.py
1 parent 8e96079 commit 584ff08

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Color_Palette.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import numpy as np
55
from matplotlib import pyplot as plt
66
from matplotlib import colors as mcolors
7+
import os
78

8-
def extract_colors(image_path, num_colors=4, output_file="color_palette.pdf"):
9+
def extract_colors(image_path, num_colors=4):
910
try:
1011
# Load the image
1112
image = Image.open(image_path)
@@ -41,6 +42,10 @@ def extract_colors(image_path, num_colors=4, output_file="color_palette.pdf"):
4142
ax.set_ylim(0, 1)
4243
ax.axis('off')
4344

45+
# Determine output file path
46+
output_dir = os.path.dirname(image_path)
47+
output_file = os.path.join(output_dir, "color_palette.pdf")
48+
4449
# Save the palette to a PDF file
4550
plt.savefig(output_file, bbox_inches='tight')
4651
plt.close()

0 commit comments

Comments
 (0)