Skip to content

Commit

Permalink
Allow set null for one width or height in ThumbConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
itstructure committed Sep 12, 2020
1 parent 08d57c7 commit dc558b4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -44,7 +44,7 @@ Addition module description you can see in my [Personal site](https://pack-devel

Via composer:

`composer require itstructure/yii2-multi-format-uploader ~3.2.0`
`composer require itstructure/yii2-multi-format-uploader ~3.2.1`

### If you are testing this package from local server directory

Expand Down
3 changes: 3 additions & 0 deletions changelog.md
@@ -1,5 +1,8 @@
### CHANGE LOG:

**3.2.1 September 12, 2020:**
- Allow set `null` for one width or height in ThumbConfig.

**3.2.0 September 12, 2020:**
- Optimize `deleteMediafiles()` method in `MediaFilesTrait`. Add protection to physical delete multiplied files, which are related more then one owner.
- Optimize owner's entity classes.
Expand Down
8 changes: 4 additions & 4 deletions src/Module.php
Expand Up @@ -323,9 +323,9 @@ public static function configureThumb(string $alias, array $config): ThumbConfig
if (!isset($config['name']) ||
!isset($config['size']) ||
!is_array($config['size']) ||
!isset($config['size'][0]) ||
!isset($config['size'][1])) {

(!isset($config['size'][0]) && !is_null($config['size'][0])) ||
(!isset($config['size'][1]) && !is_null($config['size'][1]))
) {
throw new InvalidConfigException('Error in thumb configuration.');
}

Expand All @@ -335,7 +335,7 @@ public static function configureThumb(string $alias, array $config): ThumbConfig
'name' => $config['name'],
'width' => $config['size'][0],
'height' => $config['size'][1],
'mode' => (isset($config['mode']) ? $config['mode'] : ImageInterface::THUMBNAIL_OUTBOUND),
'mode' => (!empty($config['mode']) ? $config['mode'] : ImageInterface::THUMBNAIL_OUTBOUND),
];

/* @var ThumbConfigInterface $object */
Expand Down
12 changes: 6 additions & 6 deletions src/components/ThumbConfig.php
Expand Up @@ -36,14 +36,14 @@ class ThumbConfig implements ThumbConfigInterface
/**
* Thumb width.
*
* @var
* @var int|null
*/
public $width;

/**
* Thumb height.
*
* @var
* @var int|null
*/
public $height;

Expand Down Expand Up @@ -77,19 +77,19 @@ public function getName(): string
/**
* Get thumb width.
*
* @return int
* @return int|null
*/
public function getWidth(): int
public function getWidth()
{
return $this->width;
}

/**
* Get thumb height.
*
* @return int
* @return int|null
*/
public function getHeight(): int
public function getHeight()
{
return $this->height;
}
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/ThumbConfigInterface.php
Expand Up @@ -28,16 +28,16 @@ public function getName(): string ;
/**
* Get thumb width.
*
* @return int
* @return int|null
*/
public function getWidth(): int ;
public function getWidth();

/**
* Get thumb height.
*
* @return int
* @return int|null
*/
public function getHeight(): int ;
public function getHeight();

/**
* Get thumb mode.
Expand Down
12 changes: 6 additions & 6 deletions src/models/upload/LocalUpload.php
Expand Up @@ -155,15 +155,15 @@ protected function createThumb(ThumbConfigInterface $thumbConfig)
DIRECTORY_SEPARATOR .
$this->getThumbFilename($originalFile['filename'],
$originalFile['extension'],
$thumbConfig->alias,
$thumbConfig->width,
$thumbConfig->height
$thumbConfig->getAlias(),
$thumbConfig->getWidth(),
$thumbConfig->getHeight()
);

Image::thumbnail($this->uploadRoot . DIRECTORY_SEPARATOR . ltrim(ltrim($this->mediafileModel->url, '\\'), '/'),
$thumbConfig->width,
$thumbConfig->height,
$thumbConfig->mode
$thumbConfig->getWidth(),
$thumbConfig->getHeight(),
$thumbConfig->getMode()
)->save($this->uploadRoot . DIRECTORY_SEPARATOR . ltrim(ltrim($thumbUrl, '\\'), '/'));

return $thumbUrl;
Expand Down

0 comments on commit dc558b4

Please sign in to comment.