attempt to fix dealing with 4 channel color
@@ -82,17 +82,16 @@ class Palette:
img = cv2.imread(self.source_dir + image_file, cv2.IMREAD_UNCHANGED)
- if "copper" in image_file.lower():
- print(img.shape)
-
if img is None:
return False
- # if len(img[0][0]) > 3:
- # for row in img:
- # for pixel in row:
- # if pixel[3] < 220:
- # return False
+ if img.shape[2] == 4:
+ for row in img:
+ for pixel in row:
+ if pixel[3] < 255:
+ return False
+
+ img = cv2.imread(self.source_dir + image_file, cv2.IMREAD_COLOR)
if img.shape[1] != self.dest_dims[1] or img.shape[0] != self.dest_dims[0]:
# img = cv2.resize(img, self.dest_dims)
@@ -114,10 +113,7 @@ class Palette:
for i in range(img.shape[2]):
avgs[i] /= p_count
- if len(avgs) == 4:
- avgs = avgs[:-1]
- else:
- avgs = avgs[::-1]
+ avgs.reverse()
b = base64.b64encode(cv2.imencode(".png", img)[1]).decode("utf-8")
