Skip to content

Commit

Permalink
PB-302: Change resize icon logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoss committed Aug 30, 2024
1 parent d928cee commit 1832ea4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/helpers/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_icon_template_url(base_url='', with_color=True):
f"@{{icon_scale}}{color_part}.png"


def calculate_icon_size(size, icon_set, scale=1):
def calculate_icon_size(size, scale=1):
"""
Calculate icon size so that the size of the smaller dimension is equal to the standard icon size
multiplied by the scaling
Expand Down
2 changes: 1 addition & 1 deletion app/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_size(self):
A tuple with the size of the specified icon (x,y)
"""
with Image.open(self.get_icon_filepath()) as img:
return calculate_icon_size(img.size, self.icon_set)
return calculate_icon_size(img.size)

def serialize(self):
"""
Expand Down
6 changes: 2 additions & 4 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from app.icon_set import IconSet
from app.icon_set import get_all_icon_sets
from app.settings import DEFAULT_COLOR
from app.settings import DEFAULT_ICON_SIZE
from app.version import APP_VERSION

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -97,9 +96,8 @@ def colorized_icon(
if image.mode == 'P':
image = image.convert('RGBA')

new_size = calculate_icon_size(image.size, icon_set, scale)
if min(new_size[0], new_size[1]) != DEFAULT_ICON_SIZE:
image = image.resize((new_size[0], new_size[1]))
new_size = calculate_icon_size(image.size, scale)
image = image.resize((new_size[0], new_size[1]))
if icon_set.colorable:
image = Image.composite(Image.new("RGB", image.size, (red, green, blue)), image, image)
output = BytesIO()
Expand Down

0 comments on commit 1832ea4

Please sign in to comment.