Permalink
Browse files

Adding new a couple new filters for images so some effects can applie…

…d to them.
  • Loading branch information...
meenie committed Mar 23, 2013
1 parent 815af23 commit f59faa069c816880dbdaab3b1c3e68718669099f
@@ -0,0 +1,48 @@
<?php
/**
* Munee: Optimising Your Assets
*
* @copyright Cody Lundquist 2013
* @license http://opensource.org/licenses/mit-license.php
*/
namespace Munee\Asset\Filter\Image;
use Munee\Asset\Filter;
use Imagine\Gd\Imagine;
use Imagine\Image\Color;
/**
* Colorize Filter for Images
*
* @author Cody Lundquist
*/
class Colorize extends Filter
{
/**
* @var array
*/
protected $_allowedParams = array(
'colorize' => array(
'regex' => '[A-Fa-f0-9]{3}$|^[A-Fa-f0-9]{6}',
'cast' => 'string'
)
);
/**
* Turn an image Grayscale
*
* @param string $file
* @param array $arguments
*
* @return void
*/
public function doFilter($file, $arguments)
{
$Imagine = new Imagine();
$image = $Imagine->open($file);
$colour = new Color('#' . $arguments['colorize']);
$image->effects()->colorize($colour);
$image->save($file);
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Munee: Optimising Your Assets
*
* @copyright Cody Lundquist 2013
* @license http://opensource.org/licenses/mit-license.php
*/
namespace Munee\Asset\Filter\Image;
use Munee\Asset\Filter;
use Imagine\Gd\Imagine;
/**
* Grayscale Filter for Images
*
* @author Cody Lundquist
*/
class Grayscale extends Filter
{
/**
* @var array
*/
protected $_allowedParams = array(
'grayscale' => array(
'regex' => 'true|false|t|f|yes|no|y|n',
'default' => 'false',
'cast' => 'boolean'
)
);
/**
* Turn an image Grayscale
*
* @param string $file
* @param array $arguments
*
* @return void
*/
public function doFilter($file, $arguments)
{
if (! $arguments['grayscale']) {
return;
}
$Imagine = new Imagine();
$image = $Imagine->open($file);
$image->effects()->grayscale();
$image->save($file);
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Munee: Optimising Your Assets
*
* @copyright Cody Lundquist 2013
* @license http://opensource.org/licenses/mit-license.php
*/
namespace Munee\Asset\Filter\Image;
use Munee\Asset\Filter;
use Imagine\Gd\Imagine;
/**
* Negative Filter for Images
*
* @author Cody Lundquist
*/
class Negative extends Filter
{
/**
* @var array
*/
protected $_allowedParams = array(
'negative' => array(
'regex' => 'true|false|t|f|yes|no|y|n',
'cast' => 'string'
)
);
/**
* Turn an image Grayscale
*
* @param string $file
* @param array $arguments
*
* @return void
*/
public function doFilter($file, $arguments)
{
$Imagine = new Imagine();
$image = $Imagine->open($file);
$image->effects()->negative();
$image->save($file);
}
}
@@ -10,6 +10,7 @@
use Munee\Asset\Filter;
use Munee\ErrorException;
use Imagine\Gd\Imagine;
use Imagine\Image\ImageInterface;
use Imagine\Image\Box;
use Imagine\Image\Color;
@@ -27,10 +28,9 @@ class Resize extends Filter
*/
protected $_allowedParams = array(
'resize' => array(
'alias' => 'r',
'arguments' => array(
'width' => array(
'alias' => array('w'),
'alias' => 'w',
'regex' => '\d+',
'cast' => 'integer'
),
@@ -74,7 +74,7 @@ class Resize extends Filter
'fill_colour',
'fill-colour'
),
'regex' => '[A-Fa-f0-9]{3,6}',
'regex' => '[A-Fa-f0-9]{3}$|^[A-Fa-f0-9]{6}',
'default' => 'ffffff',
'cast' => 'string'
)
@@ -99,7 +99,7 @@ public function doFilter($originalImage, $arguments)
throw new ErrorException('You must set at least the height (h) or the width (w)');
}
$Imagine = new \Imagine\Gd\Imagine();
$Imagine = new Imagine();
$image = $Imagine->open($originalImage);
$size = $image->getSize();

0 comments on commit f59faa0

Please sign in to comment.