Skip to content

Fix aspect ratio preservation when creating folder icons from non-square images - #9

Draft
moxwel with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-7
Draft

Fix aspect ratio preservation when creating folder icons from non-square images#9
moxwel with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-7

Conversation

Copilot AI commented Jul 2, 2025

Copy link
Copy Markdown

Problem

When using non-square images (like 350x80), the folder icon generation would stretch them to fit exact square dimensions, causing visual distortion. Circles became ovals, text appeared compressed, and the overall quality was poor.

Example of the issue:
Original issue showing stretched image

Solution

Fixed the prepareLabel function in src/image.py to preserve aspect ratio when resizing images. Changed from resize(width, height) which stretches images to exact dimensions, to transform(resize='WxH') which preserves aspect ratio while fitting within target dimensions.

Code changes (5 lines):

# Before (stretches image):
ico_img_big.resize(135,135)
ico_img_sml.resize(16,16) 
ico_img_min.resize(10,10)

# After (preserves aspect ratio):
ico_img_big.transform(resize='135x135')
ico_img_sml.transform(resize='16x16')
ico_img_min.transform(resize='10x10')

Results

Horizontal images: Aspect ratio preserved correctly
Vertical images: Aspect ratio preserved correctly
Square images: Continue to work perfectly
Extreme ratios: Handled gracefully (e.g., 10x200 → 1px width when needed)
All icon sizes: 10px, 16px, and 135px variants all working properly
Shadow effects: Work correctly with preserved aspect ratios

Visual demonstration:
Aspect Ratio Fix Demonstration

The fix is minimal and surgical - only changes the resize method calls without affecting other functionality. No existing behavior is broken, and the change maintains backward compatibility.

Fixes #7.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 2, 2025 21:50
Co-authored-by: moxwel <49621788+moxwel@users.noreply.github.com>
Co-authored-by: moxwel <49621788+moxwel@users.noreply.github.com>
Copilot AI changed the title [WIP] Image don't preserve aspect ratio in icon Fix aspect ratio preservation when creating folder icons from non-square images Jul 2, 2025
Copilot finished work on behalf of moxwel July 2, 2025 21:57
Copilot AI requested a review from moxwel July 2, 2025 21:57
@moxwel

moxwel commented Jul 2, 2025

Copy link
Copy Markdown
Owner

ImageMagick 7 uses "truecoloralpha" instead of "truecolormatte".
Make the anchor point of the resized label image to the bottom right corner.

Co-authored-by: moxwel <49621788+moxwel@users.noreply.github.com>

Copilot AI commented Jul 2, 2025

Copy link
Copy Markdown
Author

ImageMagick 7 uses "truecoloralpha" instead of "truecolormatte".
Make the anchor point of the resized label image to the bottom right corner.

Fixed both issues in commit 508eac8:

  1. Reverted to 'truecoloralpha' for ImageMagick 7 compatibility
  2. Changed big image anchor point to use gravity='south_east' (bottom right) instead of absolute positioning

Copilot finished work on behalf of moxwel July 2, 2025 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image don't preserve aspect ratio in icon

2 participants