Skip to content

Commit

Permalink
Merge pull request #16382 from oparoz/providers-are-responsible-for-t…
Browse files Browse the repository at this point in the history
…he-size-of-their-preview

Fix max preview, some resizing and caching issues and force preview providers to resize their previews properly
  • Loading branch information
DeepDiver1975 committed Jun 8, 2015
2 parents 1769de0 + 3d0a523 commit 64c9c27
Show file tree
Hide file tree
Showing 25 changed files with 2,067 additions and 431 deletions.
24 changes: 24 additions & 0 deletions lib/private/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,8 @@ public function crop($x, $y, $w, $h) {
/**
* Resizes the image to fit within a boundary while preserving ratio.
*
* Warning: Images smaller than $maxWidth x $maxHeight will end up being scaled up
*
* @param integer $maxWidth
* @param integer $maxHeight
* @return bool
Expand All @@ -972,6 +974,28 @@ public function fitIn($maxWidth, $maxHeight) {
return true;
}

/**
* Shrinks larger images to fit within specified boundaries while preserving ratio.
*
* @param integer $maxWidth
* @param integer $maxHeight
* @return bool
*/
public function scaleDownToFit($maxWidth, $maxHeight) {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
}
$widthOrig = imageSX($this->resource);
$heightOrig = imageSY($this->resource);

if ($widthOrig > $maxWidth || $heightOrig > $maxHeight) {
return $this->fitIn($maxWidth, $maxHeight);
}

return false;
}

/**
* Destroys the current image and resets the object
*/
Expand Down
Loading

0 comments on commit 64c9c27

Please sign in to comment.