Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permanent fix for image width workaround #161

Open
kentpmckinney opened this issue Nov 11, 2023 · 0 comments
Open

Permanent fix for image width workaround #161

kentpmckinney opened this issue Nov 11, 2023 · 0 comments

Comments

@kentpmckinney
Copy link
Contributor

kentpmckinney commented Nov 11, 2023

As part of PR #157, a change was made to BadgeImage.java to increase the width of scaled images by 25%. This was done to counteract images getting shrunk horizontally by 25%. A couple of attempts were made to replace the scaling logic, but the results came out the same.

new_width = (new_height * original_width * 125 / 100) / original_height;

Investigate what is shrinking the width of these scaled images and fix. This code is related to printing physical badges and so it will not be needed further for this year.

Here is the original version of drawStretchedImage, which has the same shrinking problem:

void drawStretchedImage(Image image, Rectangle boundingArea) {
        if (image == null) return;
        double imageWidth = image.getWidth(null);
        double imageHeight = image.getHeight(null);

        double widthRatio = area.getWidth() / imageWidth;
        double heightRatio = area.getHeight() / imageHeight;
        double ratio = Math.min(widthRatio, heightRatio);

        int newWidth = (int) (imageWidth * ratio);
        int newHeight = (int) (imageHeight * ratio);

        Rectangle scaledArea = new Rectangle(
                area.x + (area.width - newWidth)/2,
                area.y + (area.height - newHeight)/2,
                newWidth,
                newHeight);
        drawImage(image, scaledArea);
}
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

No branches or pull requests

1 participant