Skip to content

Commit

Permalink
Merge pull request #1375 from scireum/feature/bko/se-13196-memory-imp…
Browse files Browse the repository at this point in the history
…act-data-sheet

Fixes scaling of images
  • Loading branch information
bkositza authored Jan 30, 2024
2 parents f70a7a3 + 487ead7 commit 1cb396e
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ private Tuple<Integer, Integer> computeResizeBox(int cssWidth, int cssHeight, FS

@Nonnull
private static Tuple<Integer, Integer> downscaleResource(int cssWidth, int cssHeight, FSImage fsImage) {
if (fsImage.getWidth() > cssWidth) {
return Tuple.create(cssWidth, (cssWidth * fsImage.getHeight()) / fsImage.getWidth());
int imageWidth = fsImage.getWidth();
int imageHeight = fsImage.getHeight();

// First, check if we need to scale down the width
if (imageWidth > cssWidth) {
imageHeight = cssWidth * imageHeight / imageWidth;
imageWidth = cssWidth;
}
return Tuple.create((cssHeight * fsImage.getWidth()) / fsImage.getHeight(), cssHeight);

// Depending on the image aspect ratio, the height might still be larger than the defined limit, so
// we scale down further
if (imageHeight > cssHeight) {
imageWidth = cssHeight * imageWidth / imageHeight;
imageHeight = cssHeight;
}

return Tuple.create(imageWidth, imageHeight);
}

@Nonnull
Expand Down

0 comments on commit 1cb396e

Please sign in to comment.