Skip to content

Commit

Permalink
add resizeImage in FileTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
PutraSudaryanto committed Jun 1, 2018
1 parent d7ec3bf commit 75bbae6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions FileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
* Contains many function that most used :
* formatFileType
* createUploadDirectory
* resizeImage
*
*/

namespace ommu\traits;

use Yii;
use yii\imagine\Image;

trait FileTrait
{
/**
Expand Down Expand Up @@ -67,4 +71,15 @@ public function createUploadDirectory($path, $key=null)

return true;
}

/**
* Resize and creates a thumbnail image.
*/
public function resizeImage($image, $width, $height, $quality=80)
{
$width = $width ? $width : null;
$height = $height ? $height : null;

Image::thumbnail($image, $width, $height)->save($image, ['quality' => $quality]);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"require": {
"php": "~7.0",
"oomphinc/composer-installers-extender": "^1.0",
"yiisoft/yii2": "~2.0.13"
"yiisoft/yii2": "~2.0.13",
"yiisoft/yii2-imagine": "~2.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 75bbae6

Please sign in to comment.