Commit a8cc83c3 authored by Nicolas Widart's avatar Nicolas Widart

Adding default options

parent 636d840d
...@@ -4,7 +4,9 @@ return [ ...@@ -4,7 +4,9 @@ return [
'smallThumb' => [ 'smallThumb' => [
'crop' => [ 'crop' => [
'width' => '200', 'width' => '200',
'height' => '250' 'height' => '250',
'x' => 0,
'y' => 0
], ],
'blur' => [ 'blur' => [
'amount' => '15' 'amount' => '15'
......
<?php namespace Modules\Media\Image\Intervention\Manipulations; <?php namespace Modules\Media\Image\Intervention\Manipulations;
use InvalidArgumentException;
use Modules\Media\Image\ImageHandlerInterface; use Modules\Media\Image\ImageHandlerInterface;
class Blur implements ImageHandlerInterface class Blur implements ImageHandlerInterface
{ {
private $defaults = [
'amount' => 1
];
/** /**
* Handle the image manipulation request * Handle the image manipulation request
* @param \Intervention\Image\Image $image * @param \Intervention\Image\Image $image
...@@ -13,9 +16,7 @@ class Blur implements ImageHandlerInterface ...@@ -13,9 +16,7 @@ class Blur implements ImageHandlerInterface
*/ */
public function handle($image, $options) public function handle($image, $options)
{ {
if (!isset($options['amount'])) { $options = array_merge($this->defaults, $options);
throw new InvalidArgumentException('An amount option is required');
}
return $image->blur($options['amount']); return $image->blur($options['amount']);
} }
......
<?php namespace Modules\Media\Image\Intervention\Manipulations; <?php namespace Modules\Media\Image\Intervention\Manipulations;
use InvalidArgumentException;
use Modules\Media\Image\ImageHandlerInterface; use Modules\Media\Image\ImageHandlerInterface;
class Crop implements ImageHandlerInterface class Crop implements ImageHandlerInterface
{ {
private $defaults = [
'width' => '100',
'height' => '100',
'x' => null,
'y' => null,
];
/** /**
* Handle the image manipulation request * Handle the image manipulation request
* @param \Intervention\Image\Image $image * @param \Intervention\Image\Image $image
...@@ -13,10 +19,8 @@ class Crop implements ImageHandlerInterface ...@@ -13,10 +19,8 @@ class Crop implements ImageHandlerInterface
*/ */
public function handle($image, $options) public function handle($image, $options)
{ {
if (!isset($options['width']) or !isset($options['height'])) { $options = array_merge($this->defaults, $options);
throw new InvalidArgumentException('A width and height parameter are required');
}
return $image->crop($options['width'], $options['height']); return $image->crop($options['width'], $options['height'], $options['x'], $options['y']);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment