[MAGNOLIA-3734] Preview in file upload control does not scale down perfectly square images Created: 10/Jun/11  Updated: 03/Jan/13  Resolved: 20/Dec/12

Status: Closed
Project: Magnolia
Component/s: admininterface, gui, templating
Affects Version/s: 4.4.4, 4.5
Fix Version/s: 4.4.10, 4.5.8

Type: Bug Priority: Neutral
Reporter: Tobias Mattsson Assignee: Roman Kovařík
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: JPEG File square_image.jpg    
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 Description   

When the image is perfectly square, like 600x600, its not scaled to fit inside the 150x150 area that the preview should fit into. The code is this, in DialogFile.java:

                    // resize if to big
                    if(imgwidth > imgheight && imgwidth > 150){
                        imgheight = (int)(150.0/imgwidth * imgheight);
                        imgwidth = 150;
                    }
                    else if(imgheight > imgwidth && imgheight > 150){
                        imgwidth = (int)(150.0/imgheight * imgwidth);
                        imgheight = 150;
                    }

It should be fixable by changing to:

                    // resize if to big
                    if(imgwidth == imgheight && imgwidth > 150){
                        imgwidth = 150;
                        imgheight = 150;
                    } else if(imgwidth > imgheight && imgwidth > 150){
                        imgheight = (int)(150.0/imgwidth * imgheight);
                        imgwidth = 150;
                    }
                    else if(imgheight > imgwidth && imgheight > 150){
                        imgwidth = (int)(150.0/imgheight * imgwidth);
                        imgheight = 150;
                    }

I've attached an image that can be used to demonstrate the problem.


Generated at Mon Feb 12 03:49:10 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.