Skip to content

Commit 64c9c27

Browse files
committed
Merge pull request #16382 from oparoz/providers-are-responsible-for-the-size-of-their-preview
Fix max preview, some resizing and caching issues and force preview providers to resize their previews properly
2 parents 1769de0 + 3d0a523 commit 64c9c27

25 files changed

+2067
-431
lines changed

lib/private/image.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ public function crop($x, $y, $w, $h) {
952952
/**
953953
* Resizes the image to fit within a boundary while preserving ratio.
954954
*
955+
* Warning: Images smaller than $maxWidth x $maxHeight will end up being scaled up
956+
*
955957
* @param integer $maxWidth
956958
* @param integer $maxHeight
957959
* @return bool
@@ -972,6 +974,28 @@ public function fitIn($maxWidth, $maxHeight) {
972974
return true;
973975
}
974976

977+
/**
978+
* Shrinks larger images to fit within specified boundaries while preserving ratio.
979+
*
980+
* @param integer $maxWidth
981+
* @param integer $maxHeight
982+
* @return bool
983+
*/
984+
public function scaleDownToFit($maxWidth, $maxHeight) {
985+
if (!$this->valid()) {
986+
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
987+
return false;
988+
}
989+
$widthOrig = imageSX($this->resource);
990+
$heightOrig = imageSY($this->resource);
991+
992+
if ($widthOrig > $maxWidth || $heightOrig > $maxHeight) {
993+
return $this->fitIn($maxWidth, $maxHeight);
994+
}
995+
996+
return false;
997+
}
998+
975999
/**
9761000
* Destroys the current image and resets the object
9771001
*/

0 commit comments

Comments
 (0)