Skip to content

Commit

Permalink
GD added
Browse files Browse the repository at this point in the history
  • Loading branch information
Renoise authored and Renoise committed Jul 22, 2014
1 parent a77621f commit e945444
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class Module extends \yii\base\Module

public $imagesCachePath = '@app/web/imgCache';

public $graphicsLibrary = 'GD';

public $controllerNamespace = 'rico\yii2images\controllers';




public function getImage($item, $dirtyAlias)
{
//Get params
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
],
"minimum-stability": "dev",
"require": {
"yiisoft/yii2": "*"
"yiisoft/yii2": "*",
"abeautifulsite/simpleimage": "*"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
Expand Down
63 changes: 43 additions & 20 deletions models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,6 @@ public function createVersion($imagePath, $sizeString = false)
throw new \Exception('Image without urlAlias!');
}

$image = new \Imagick($imagePath);
$image->setImageCompressionQuality(100);

if($sizeString){
$size = $this->getModule()->parseSize($sizeString);
//p($size);die;
if($size){
if($size['height'] && $size['width']){
$image->cropThumbnailImage($size['width'], $size['height']);
}elseif($size['height']){
$image->thumbnailImage(0, $size['height']);
}elseif($size['width']){
$image->thumbnailImage($size['width'], 0);
}else{
throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
}
}
}

$cachePath = $this->getModule()->getCachePath();
$subDirPath = $this->getSubDur();
$fileExtension = pathinfo($this->filePath, PATHINFO_EXTENSION);
Expand All @@ -156,7 +137,49 @@ public function createVersion($imagePath, $sizeString = false)

BaseFileHelper::createDirectory(dirname($pathToSave), 0777, true);

$image->writeImage($pathToSave);

if($sizeString) {
$size = $this->getModule()->parseSize($sizeString);
}else{
$size = false;
}

if($this->getModule()->graphicsLibrary == 'Imagick'){
$image = new \Imagick($imagePath);
$image->setImageCompressionQuality(100);

if($size){
if($size['height'] && $size['width']){
$image->cropThumbnailImage($size['width'], $size['height']);
}elseif($size['height']){
$image->thumbnailImage(0, $size['height']);
}elseif($size['width']){
$image->thumbnailImage($size['width'], 0);
}else{
throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
}
}

$image->writeImage($pathToSave);
}else{
if($size){
$image = new \abeautifulsite\SimpleImage($imagePath);

if($size['height'] && $size['width']){

$image->thumbnail($size['width'], $size['height']);
}elseif($size['height']){
$image->fit_to_height($size['height']);
}elseif($size['width']){
$image->fit_to_width($size['width']);
}else{
throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
}
}

$image->save($pathToSave);
}


return $image;

Expand Down

0 comments on commit e945444

Please sign in to comment.