Skip to content

Permanent fix for image width workaround #161

@kentpmckinney

Description

@kentpmckinney

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions