Skip to content

Commit

Permalink
Merge pull request #20 from AleksandrChernyavenko/master
Browse files Browse the repository at this point in the history
Add ability to set thumbnail mode
  • Loading branch information
mohorev committed Aug 27, 2015
2 parents a91d7d4 + fac47a0 commit dca58ec
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions UploadImageBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace mongosoft\file;

use Imagine\Image\ManipulatorInterface;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
Expand Down Expand Up @@ -159,7 +160,7 @@ public function getThumbUploadUrl($attribute, $profile = 'thumb')
{
/** @var BaseActiveRecord $model */
$model = $this->owner;
$path = $this->getUploadPath($this->attribute, true);
$path = $this->getUploadPath($attribute, true);
if (is_file($path)) {
if ($this->createThumbsOnRequest) {
$this->createThumbs();
Expand Down Expand Up @@ -231,6 +232,7 @@ protected function generateImageThumb($config, $path, $thumbPath)
$width = ArrayHelper::getValue($config, 'width');
$height = ArrayHelper::getValue($config, 'height');
$quality = ArrayHelper::getValue($config, 'quality', 100);
$mode = ArrayHelper::getValue($config, 'mode', ManipulatorInterface::THUMBNAIL_INSET);

if (!$width || !$height) {
$image = Image::getImagine()->open($path);
Expand All @@ -244,6 +246,6 @@ protected function generateImageThumb($config, $path, $thumbPath)

// Fix error "PHP GD Allowed memory size exhausted".
ini_set('memory_limit', '512M');
Image::thumbnail($path, $width, $height)->save($thumbPath, ['quality' => $quality]);
Image::thumbnail($path, $width, $height, $mode)->save($thumbPath, ['quality' => $quality]);
}
}

0 comments on commit dca58ec

Please sign in to comment.