Skip to content

Commit

Permalink
Fix order of operations in processing image
Browse files Browse the repository at this point in the history
  • Loading branch information
ehashman committed Oct 27, 2020
1 parent edc406d commit 9c5314e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ih/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def preprocess_image(
scale=DEFAULT["scale"],
guidelines=DEFAULT["guidelines"],
):
# Reduce palette to max 256 colors
reduced_palette = palette.reduce_palette(palette=pal, image=im)
palette_image = palette.get_palette_image(reduced_palette)
im = im.resize((int(im.width / scale), int(im.height / scale)))

# Remove black transparency issues with this one weird trick.
alpha = im.convert("RGBA").split()[-1]
bg = Image.new("RGBA", im.size, (255, 255, 255, 255))
bg.paste(im, mask=alpha)
im = bg

# Reduce palette
reduced_palette = palette.reduce_palette(palette=pal, image=im) # cap palette size at 256
palette_image = palette.get_palette_image(reduced_palette)
im = im.resize((int(im.width / scale), int(im.height / scale)))

im = (
im.convert("RGB")
.convert("P", palette=Image.ADAPTIVE, colors=colors)
Expand Down

0 comments on commit 9c5314e

Please sign in to comment.