Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
new mode THUMBNAIL_INSET_BOX
Browse files Browse the repository at this point in the history
  • Loading branch information
himiklab committed Nov 12, 2018
1 parent 9bad5bb commit 3a08e8c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion EasyThumbnailImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace himiklab\thumbnail;

use Imagine\Image\Box;
use Imagine\Image\ManipulatorInterface;
use Yii;
use yii\base\InvalidConfigException;
Expand All @@ -24,6 +25,7 @@ class EasyThumbnailImage
{
const THUMBNAIL_OUTBOUND = ManipulatorInterface::THUMBNAIL_OUTBOUND;
const THUMBNAIL_INSET = ManipulatorInterface::THUMBNAIL_INSET;
const THUMBNAIL_INSET_BOX = 'inset_box';
const QUALITY = 50;
const MKDIR_MODE = 0755;

Expand Down Expand Up @@ -59,6 +61,11 @@ class EasyThumbnailImage
* [[Image::$thumbnailBackgroundColor]] or [[EasyThumbnail::$thumbnailBackgroundColor]],
* and [[Image::$thumbnailBackgroundAlpha]] or [[EasyThumbnail::$thumbnailBackgroundAlpha]].
*
* If thumbnail mode is `self::THUMBNAIL_INSET_BOX`, the original image is scaled down so it is fully contained
* within the thumbnail dimensions. The specified $width and $height (supplied via $size) will be considered
* maximum limits. Unless the given dimensions are equal to the original image’s aspect ratio, one dimension in the
* resulting thumbnail will be smaller than the given limit.
*
* @param string $filename the image file path or path alias or URL
* @param integer $width the width in pixels to create the thumbnail
* @param integer $height the height in pixels to create the thumbnail
Expand Down Expand Up @@ -96,6 +103,11 @@ public static function thumbnail($filename, $width, $height, $mode = self::THUMB
* [[Image::$thumbnailBackgroundColor]] or [[EasyThumbnail::$thumbnailBackgroundColor]],
* and [[Image::$thumbnailBackgroundAlpha]] or [[EasyThumbnail::$thumbnailBackgroundAlpha]].
*
* If thumbnail mode is `self::THUMBNAIL_INSET_BOX`, the original image is scaled down so it is fully contained
* within the thumbnail dimensions. The specified $width and $height (supplied via $size) will be considered
* maximum limits. Unless the given dimensions are equal to the original image’s aspect ratio, one dimension in the
* resulting thumbnail will be smaller than the given limit.
*
* @param string $filename the image file path or path alias or URL
* @param integer $width the width in pixels to create the thumbnail
* @param integer $height the height in pixels to create the thumbnail
Expand Down Expand Up @@ -160,7 +172,11 @@ public static function thumbnailFile($filename, $width, $height, $mode = self::T
} else {
$image = Image::getImagine()->open($filename);
}
$image = Image::thumbnail($image, $width, $height, $mode);
if ($mode === self::THUMBNAIL_INSET_BOX) {
$image = $image->thumbnail(new Box($width, $height), ManipulatorInterface::THUMBNAIL_INSET);
} else {
$image = Image::thumbnail($image, $width, $height, $mode);
}

$options = [
'quality' => $quality === null ? self::QUALITY : $quality
Expand Down Expand Up @@ -189,6 +205,11 @@ public static function thumbnailFile($filename, $width, $height, $mode = self::T
* [[Image::$thumbnailBackgroundColor]] or [[EasyThumbnail::$thumbnailBackgroundColor]],
* and [[Image::$thumbnailBackgroundAlpha]] or [[EasyThumbnail::$thumbnailBackgroundAlpha]].
*
* If thumbnail mode is `self::THUMBNAIL_INSET_BOX`, the original image is scaled down so it is fully contained
* within the thumbnail dimensions. The specified $width and $height (supplied via $size) will be considered
* maximum limits. Unless the given dimensions are equal to the original image’s aspect ratio, one dimension in the
* resulting thumbnail will be smaller than the given limit.
*
* @param string $filename the image file path or path alias or URL
* @param integer $width the width in pixels to create the thumbnail
* @param integer $height the height in pixels to create the thumbnail
Expand Down

0 comments on commit 3a08e8c

Please sign in to comment.