Skip to content

Commit

Permalink
Merge branch '4.x' of https://github.com/craftcms/cms into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 3, 2025
2 parents 9a00652 + 9bbd9e7 commit ca0a045
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug where transformed images could be slightly smaller than they should be when using the `fit` transform mode. ([#16622](https://github.com/craftcms/cms/issues/16622))
- Fixed a bug where section-specific GraphQL queries (`<sectionHandle>Entries`) weren’t available if a Matrix or CKEditor field existed with the same handle as the section.
- Fixed an error that could occur after reordering routes. ([#16610](https://github.com/craftcms/cms/pull/16610))
- Fixed an error that occurred when a non-admin user attempted to copy a field value from another site.
Expand Down
10 changes: 8 additions & 2 deletions src/image/Raster.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,14 @@ public function scaleToFit(?int $targetWidth, ?int $targetHeight, bool $scaleIfS
$scaleIfSmaller = $scaleIfSmaller ?? Craft::$app->getConfig()->getGeneral()->upscaleImages;

if ($scaleIfSmaller || $this->getWidth() > $targetWidth || $this->getHeight() > $targetHeight) {
$factor = max($this->getWidth() / $targetWidth, $this->getHeight() / $targetHeight);
$this->resize(round($this->getWidth() / $factor), round($this->getHeight() / $factor));
// go with the provided target dimensions if they both check out
if ((int)round($targetWidth * $this->getHeight() / $this->getWidth()) !== $targetHeight) {
$factor = max($this->getWidth() / $targetWidth, $this->getHeight() / $targetHeight);
$targetWidth = round($this->getWidth() / $factor);
$targetHeight = round($this->getHeight() / $factor);
}

$this->resize($targetWidth, $targetHeight);
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/helpers/ImageHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ public static function calculateMissingDimensionDataProvider(): array
[[28971, 14341], 28971.251, 0, 4.2891, 2.12321],
[[2491030, 1233121], 0, 1233121.123213, 4.2891, 2.12321],
[[12, 1233121], 12.12, 1233121.123213, 0, 4324],
// https://github.com/craftcms/cms/issues/16622
[[840, 484], 840, null, 1375, 793],
];
}

Expand Down

0 comments on commit ca0a045

Please sign in to comment.