1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-19 12:11:26 +02:00

Added DocBlocks

This commit is contained in:
Oliver Vogel
2014-05-14 20:13:53 +02:00
parent eae9d83f8a
commit e8e7251b9d
103 changed files with 1872 additions and 17 deletions

View File

@@ -4,23 +4,113 @@ namespace Intervention\Image;
abstract class AbstractColor
{
/**
* Initiates color object from integer
*
* @param integer $value
* @return Intervention\Image\AbstractColor
*/
abstract public function initFromInteger($value);
/**
* Initiates color object from given array
*
* @param array $value
* @return Intervention\Image\AbstractColor
*/
abstract public function initFromArray($value);
/**
* Initiates color object from given string
*
* @param string $value
* @return Intervention\Image\AbstractColor
*/
abstract public function initFromString($value);
/**
* Initiates color object from given ImagickPixel object
*
* @param ImagickPixel $value
* @return Intervention\Image\AbstractColor
*/
abstract public function initFromObject($value);
/**
* Initiates color object from given R, G and B values
*
* @param integer $r
* @param integer $g
* @param integer $b
* @return Intervention\Image\AbstractColor
*/
abstract public function initFromRgb($r, $g, $b);
/**
* Initiates color object from given R, G, B and A values
*
* @param integer $r
* @param integer $g
* @param integer $b
* @param float $a
* @return Intervention\Image\AbstractColor
*/
abstract public function initFromRgba($r, $g, $b, $a);
/**
* Calculates integer value of current color instance
*
* @return integer
*/
abstract public function getInt();
/**
* Calculates hexadecimal value of current color instance
*
* @param string $prefix
* @return string
*/
abstract public function getHex($prefix);
/**
* Calculates RGB(A) in array format of current color instance
*
* @return array
*/
abstract public function getArray();
/**
* Calculates RGBA in string format of current color instance
*
* @return string
*/
abstract public function getRgba();
/**
* Determines if current color is different from given color
*
* @param AbstractColor $color
* @param integer $tolerance
* @return boolean
*/
abstract public function differs(AbstractColor $color, $tolerance = 0);
/**
* Creates new instance
*
* @param string $value
*/
public function __construct($value = null)
{
$this->parse($value);
}
/**
* Parses given value as color
*
* @param mixed $value
* @return Intervention\Image\AbstractColor
*/
public function parse($value)
{
switch (true) {
@@ -55,6 +145,12 @@ abstract class AbstractColor
return $this;
}
/**
* Formats current color instance into given format
*
* @param string $type
* @return mixed
*/
public function format($type)
{
switch (strtolower($type)) {
@@ -89,6 +185,12 @@ abstract class AbstractColor
}
}
/**
* Reads RGBA values from string into array
*
* @param string $value
* @return array
*/
protected function rgbaFromString($value)
{
$result = false;

View File

@@ -4,19 +4,70 @@ namespace Intervention\Image;
abstract class AbstractDriver
{
/**
* Source instance to init images from
*
* @var Intervention\Image\AbstractSource
*/
public $source;
/**
* Image encoder instance
*
* @var Intervention\Image\AbstractEncoder
*/
public $encoder;
/**
* Creates new image instance
*
* @param integer $width
* @param integer $height
* @param string $background
* @return Intervention\Image\Image
*/
abstract public function newImage($width, $height, $background);
/**
* Reads given string into color object
*
* @param string $value
* @return AbstractColor
*/
abstract public function parseColor($value);
/**
* Initiates new image from given input
*
* @param mixed $data
* @return Intervention\Image\Image
*/
public function init($data)
{
return $this->source->init($data);
}
/**
* Encodes given image
*
* @param Image $image
* @param string $format
* @param integer $quality
* @return Intervention\Image\Image
*/
public function encode($image, $format, $quality)
{
return $this->encoder->process($image, $format, $quality);
}
/**
* Executes named command on given image
*
* @param Image $image
* @param string $name
* @param array $arguments
* @return Intervention\Image\Commands\AbstractCommand
*/
public function executeCommand($image, $name, $arguments)
{
$commandName = $this->getCommandClassName($name);
@@ -26,6 +77,12 @@ abstract class AbstractDriver
return $command;
}
/**
* Returns classname of given command name
*
* @param string $name
* @return string
*/
private function getCommandClassName($name)
{
$drivername = $this->getDriverName();
@@ -43,6 +100,11 @@ abstract class AbstractDriver
);
}
/**
* Returns name of current driver instance
*
* @return string
*/
public function getDriverName()
{
$reflect = new \ReflectionClass($this);

View File

@@ -4,12 +4,42 @@ namespace Intervention\Image;
abstract class AbstractEncoder
{
/**
* Processes and returns encoded image as JPEG string
*
* @return string
*/
abstract protected function processJpeg();
/**
* Processes and returns encoded image as PNG string
*
* @return string
*/
abstract protected function processPng();
/**
* Processes and returns encoded image as GIF string
*
* @return string
*/
abstract protected function processGif();
/**
* Buffer of encode result data
*
* @var string
*/
public $result;
/**
* Process a given image
*
* @param Image $image
* @param string $format
* @param integer $quality
* @return Intervention\Image\Image
*/
public function process(Image $image, $format = null, $quality = null)
{
$this->setImage($image);
@@ -44,6 +74,11 @@ abstract class AbstractEncoder
return $image->setEncoded($this->result);
}
/**
* Processes and returns encoded image as data-url string
*
* @return string
*/
protected function processDataUrl()
{
return sprintf('data:%s;base64,%s',
@@ -52,11 +87,21 @@ abstract class AbstractEncoder
);
}
/**
* Sets image to process
*
* @param Intervention\Image\Image $image
*/
protected function setImage($image)
{
$this->image = $image;
}
/**
* Determines output format
*
* @param string $format
*/
protected function setFormat($format = null)
{
if (is_null($format) && $this->image instanceof Image) {
@@ -68,6 +113,11 @@ abstract class AbstractEncoder
return $this;
}
/**
* Determines output quality
*
* @param integer $quality
*/
protected function setQuality($quality)
{
$quality = is_null($quality) ? 90 : $quality;

View File

@@ -4,6 +4,14 @@ namespace Intervention\Image;
abstract class AbstractFont
{
/**
* Draws font to given image on given position
*
* @param Image $image
* @param integer $posx
* @param integer $posy
* @return boolean
*/
abstract public function applyToImage(Image $image, $posx = 0, $posy = 0);
/**

View File

@@ -4,16 +4,41 @@ namespace Intervention\Image;
abstract class AbstractShape
{
/**
* Background color of shape
*
* @var string
*/
public $background;
/**
* Border color of current shape
*
* @var string
*/
public $border_color;
/**
* Border width of shape
*
* @var integer
*/
public $border_width = 0;
/**
* Draws shape to given image on given position
*
* @param Image $image
* @param integer $posx
* @param integer $posy
* @return boolean
*/
abstract public function applyToImage(Image $image, $posx = 0, $posy = 0);
/**
* Set text to be written
*
* @param String $text
* @param string $text
* @return void
*/
public function background($color)
@@ -21,12 +46,24 @@ abstract class AbstractShape
$this->background = $color;
}
/**
* Set border width and color of current shape
*
* @param integer $width
* @param string $color
* @return void
*/
public function border($width, $color = null)
{
$this->border_width = is_numeric($width) ? intval($width) : 0;
$this->border_color = is_null($color) ? '#000000' : $color;
}
/**
* Determines if current shape has border
*
* @return boolean
*/
public function hasBorder()
{
return ($this->border_width >= 1);

View File

@@ -4,18 +4,60 @@ namespace Intervention\Image;
abstract class AbstractSource
{
/**
* Initiates new image from path in filesystem
*
* @param string $path
* @return Intervention\Image\Image
*/
abstract public function initFromPath($path);
abstract public function initFromBinary($data);
abstract public function initFromGdResource($resource);
abstract public function initFromImagick($object);
/**
* Initiates new image from binary data
*
* @param string $data
* @return Intervention\Image\Image
*/
abstract public function initFromBinary($data);
/**
* Initiates new image from GD resource
*
* @param Resource $resource
* @return Intervention\Image\Image
*/
abstract public function initFromGdResource($resource);
/**
* Initiates new image from Imagick object
*
* @param Imagick $object
* @return Intervention\Image\Image
*/
abstract public function initFromImagick(\Imagick $object);
/**
* Buffer of input data
*
* @var mixed
*/
private $data;
/**
* Creates new Source with data
*
* @param mixed $data
*/
public function __construct($data = null)
{
$this->data = $data;
}
/**
* Determines if current source data is GD resource
*
* @return boolean
*/
public function isGdResource()
{
if (is_resource($this->data)) {
@@ -25,16 +67,31 @@ abstract class AbstractSource
return false;
}
/**
* Determines if current source data is Imagick object
*
* @return boolean
*/
public function isImagick()
{
return is_a($this->data, 'Imagick');
}
/**
* Determines if current source data is Intervention\Image\Image object
*
* @return boolean
*/
public function isInterventionImage()
{
return is_a($this->data, '\Intervention\Image\Image');
}
/**
* Determines if current source data is file path
*
* @return boolean
*/
public function isFilePath()
{
if (is_string($this->data)) {
@@ -44,11 +101,21 @@ abstract class AbstractSource
return false;
}
/**
* Determines if current source data is url
*
* @return boolean
*/
public function isUrl()
{
return (bool) filter_var($this->data, FILTER_VALIDATE_URL);
}
/**
* Determines if current source data is binary data
*
* @return boolean
*/
public function isBinary()
{
if (is_string($this->data)) {
@@ -59,11 +126,23 @@ abstract class AbstractSource
return false;
}
/**
* Initiates new Image from Intervention\Image\Image
*
* @param Image $object
* @return Intervention\Image\Image
*/
public function initFromInterventionImage($object)
{
return $object;
}
/**
* Initiates new image from mixed data
*
* @param mixed $data
* @return Intervention\Image\Image
*/
public function init($data)
{
$this->data = $data;
@@ -100,6 +179,11 @@ abstract class AbstractSource
}
}
/**
* Source object transforms to string source data
*
* @return string
*/
public function __toString()
{
return (string) $this->data;

View File

@@ -4,31 +4,74 @@ namespace Intervention\Image\Commands;
abstract class AbstractCommand
{
/**
* Arguments of command
*
* @var array
*/
public $arguments;
/**
* Output of command
*
* @var mixed
*/
protected $output;
/**
* Executes current command on given image
*
* @param Intervention\Image\Image $image
* @return mixed
*/
abstract public function execute($image);
/**
* Creates new command instance
*
* @param array $arguments
*/
public function __construct($arguments)
{
$this->arguments = $arguments;
}
/**
* Creates new argument instance from given argument key
*
* @param integer $key
* @return Intervention\Image\Commands\Argument
*/
public function argument($key)
{
return new \Intervention\Image\Commands\Argument($this, $key);
}
/**
* Returns output data of current command
*
* @return mixed
*/
public function getOutput()
{
return $this->output ? $this->output : null;
}
/**
* Determines if current instance has output data
*
* @return boolean
*/
public function hasOutput()
{
return ! is_null($this->output);
}
/**
* Sets output data of current command
*
* @param mixed $value
*/
public function setOutput($value)
{
$this->output = $value;

View File

@@ -4,21 +4,49 @@ namespace Intervention\Image\Commands;
class Argument
{
/**
* Command with arguments
*
* @var Intervention\Image\Commands\AbstractCommand
*/
public $command;
/**
* Key of argument in array
*
* @var integer
*/
public $key;
/**
* Creates new instance from given command and key
*
* @param AbstractCommand $command
* @param integer $key
*/
public function __construct(AbstractCommand $command, $key = 0)
{
$this->command = $command;
$this->key = $key;
}
/**
* Returns name of current arguments command
*
* @return string
*/
public function getCommandName()
{
preg_match("/\\\\([\w]+)Command$/", get_class($this->command), $matches);
return isset($matches[1]) ? lcfirst($matches[1]).'()' : 'Method';
}
/**
* Returns value of current argument
*
* @param mixed $default
* @return mixed
*/
public function value($default = null)
{
$arguments = $this->command->arguments;
@@ -28,6 +56,11 @@ class Argument
}
}
/**
* Defines current argument as required
*
* @return Intervention\Image\Commands\Argument
*/
public function required()
{
if ( ! array_key_exists($this->key, $this->command->arguments)) {
@@ -39,6 +72,11 @@ class Argument
return $this;
}
/**
* Determines that current argument must be of given type
*
* @return Intervention\Image\Commands\Argument
*/
public function type($type)
{
$fail = false;
@@ -93,6 +131,11 @@ class Argument
return $this;
}
/**
* Determines that current argument value must be numeric between given values
*
* @return Intervention\Image\Commands\Argument
*/
public function between($x, $y)
{
$value = $this->type('numeric')->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Commands;
class ChecksumCommand extends AbstractCommand
{
/**
* Calculates checksum of given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$colors = array();

View File

@@ -6,6 +6,12 @@ use \Closure;
class CircleCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Draw a circle centered on given image
*
* @param Intervention\Image\image $image
* @return boolean
*/
public function execute($image)
{
$x = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Closure;
class EllipseCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Draws ellipse on given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$x = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -4,6 +4,15 @@ namespace Intervention\Image\Commands;
class ExifCommand extends AbstractCommand
{
/**
* Read Exif data from the given image
*
* Note: Windows PHP Users - in order to use this method you will need to
* enable the mbstring and exif extensions within the php.ini file.
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
if ( ! function_exists('exif_read_data')) {

View File

@@ -6,6 +6,12 @@ use \Closure;
class LineCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Draws line on given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$x1 = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Closure;
class RectangleCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Draws rectangle on given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$x1 = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Response;
class ResponseCommand extends AbstractCommand
{
/**
* Builds HTTP response from given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$format = $this->argument(0)->value();

View File

@@ -6,6 +6,11 @@ use \Closure;
class TextCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Write text on given image
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$text = $this->argument(0)->required()->value();

View File

@@ -4,37 +4,86 @@ namespace Intervention\Image;
class Constraint
{
/**
* Bit value of aspect ratio constraint
*/
const ASPECTRATIO = 1;
/**
* Bit value of upsize constraint
*/
const UPSIZE = 2;
/**
* Constraint size
*
* @var Intervention\Image\Size
*/
private $size;
/**
* Integer value of fixed parameters
*
* @var integer
*/
private $fixed = 0;
/**
* Create a new constraint based on size
*
* @param Size $size
*/
public function __construct(Size $size)
{
$this->size = $size;
}
/**
* Returns current size of constraint
*
* @return Intervention\Image\Size
*/
public function getSize()
{
return $this->size;
}
/**
* Fix the given argument in current constraint
* @param integer $type
* @return void
*/
public function fix($type)
{
$this->fixed = ($this->fixed & ~(1 << $type)) | (1 << $type);
}
/**
* Checks if given argument is fixed in current constraint
*
* @param integer $type
* @return boolean
*/
public function isFixed($type)
{
return (bool) ($this->fixed & (1 << $type));
}
/**
* Fixes aspect ratio in current constraint
*
* @return void
*/
public function aspectRatio()
{
$this->fix(self::ASPECTRATIO);
}
/**
* Fixes possibility to size up in current constraint
*
* @return void
*/
public function upsize()
{
$this->fix(self::UPSIZE);

View File

@@ -4,12 +4,46 @@ namespace Intervention\Image;
class File
{
/**
* Mime type
*
* @var string
*/
public $mime;
/**
* Name of directory path
*
* @var string
*/
public $dirname;
/**
* Basename of current file
*
* @var string
*/
public $basename;
/**
* File extension of current file
*
* @var string
*/
public $extension;
/**
* File name of current file
*
* @var string
*/
public $filename;
/**
* Sets all instance properties from given path
*
* @param string $path
*/
public function setFileInfoFromPath($path)
{
$info = pathinfo($path);

View File

@@ -4,15 +4,34 @@ namespace Intervention\Image\Filters;
class DemoFilter implements FilterInterface
{
/**
* Default size of filter effects
*/
const DEFAULT_SIZE = 10;
/**
* Size of filter effects
*
* @var integer
*/
private $size;
/**
* Creates new instance of filter
*
* @param integer $size
*/
public function __construct($size = null)
{
$this->size = is_numeric($size) ? intval($size) : self::DEFAULT_SIZE;
}
/**
* Applies filter effects to given image
*
* @param Intervention\Image\Image $image
* @return Intervention\Image\Image
*/
public function applyFilter(\Intervention\Image\Image $image)
{
$image->pixelate($this->size);

View File

@@ -4,5 +4,11 @@ namespace Intervention\Image\Filters;
interface FilterInterface
{
/**
* Applies filter to given image
*
* @param Intervention\Image\Image $image
* @return Intervention\Image\Image
*/
public function applyFilter(\Intervention\Image\Image $image);
}

View File

@@ -6,11 +6,40 @@ use Intervention\Image\AbstractColor;
class Color extends AbstractColor
{
/**
* RGB Red value of current color instance
*
* @var integer
*/
public $r;
/**
* RGB Green value of current color instance
*
* @var integer
*/
public $g;
/**
* RGB Blue value of current color instance
*
* @var integer
*/
public $b;
/**
* RGB Alpha value of current color instance
*
* @var float
*/
public $a;
/**
* Initiates color object from integer
*
* @param integer $value
* @return Intervention\Image\AbstractColor
*/
public function initFromInteger($value)
{
$this->a = ($value >> 24) & 0xFF;
@@ -19,6 +48,12 @@ class Color extends AbstractColor
$this->b = $value & 0xFF;
}
/**
* Initiates color object from given array
*
* @param array $value
* @return Intervention\Image\AbstractColor
*/
public function initFromArray($array)
{
$array = array_values($array);
@@ -42,6 +77,12 @@ class Color extends AbstractColor
$this->b = $b;
}
/**
* Initiates color object from given string
*
* @param string $value
* @return Intervention\Image\AbstractColor
*/
public function initFromString($value)
{
if ($color = $this->rgbaFromString($value)) {
@@ -52,6 +93,14 @@ class Color extends AbstractColor
}
}
/**
* Initiates color object from given R, G and B values
*
* @param integer $r
* @param integer $g
* @param integer $b
* @return Intervention\Image\AbstractColor
*/
public function initFromRgb($r, $g, $b)
{
$this->r = intval($r);
@@ -60,6 +109,15 @@ class Color extends AbstractColor
$this->a = 0;
}
/**
* Initiates color object from given R, G, B and A values
*
* @param integer $r
* @param integer $g
* @param integer $b
* @param float $a
* @return Intervention\Image\AbstractColor
*/
public function initFromRgba($r, $g, $b, $a = 1)
{
$this->r = intval($r);
@@ -68,31 +126,67 @@ class Color extends AbstractColor
$this->a = $this->alpha2gd($a);
}
/**
* Initiates color object from given ImagickPixel object
*
* @param ImagickPixel $value
* @return Intervention\Image\AbstractColor
*/
public function initFromObject($value)
{
throw new \Exception('Not available');
throw new \Intervention\Image\Exception\NotSupportedException(
"GD colors cannot init from ImagickPixel objects."
);
}
/**
* Calculates integer value of current color instance
*
* @return integer
*/
public function getInt()
{
return ($this->a << 24) + ($this->r << 16) + ($this->g << 8) + $this->b;
}
/**
* Calculates hexadecimal value of current color instance
*
* @param string $prefix
* @return string
*/
public function getHex($prefix = '')
{
return sprintf('%s%02x%02x%02x', $prefix, $this->r, $this->g, $this->b);
}
/**
* Calculates RGB(A) in array format of current color instance
*
* @return array
*/
public function getArray()
{
return array($this->r, $this->g, $this->b, round(1 - $this->a / 127, 2));
}
/**
* Calculates RGBA in string format of current color instance
*
* @return string
*/
public function getRgba()
{
return sprintf('rgba(%d, %d, %d, %.2f)', $this->r, $this->g, $this->b, round(1 - $this->a / 127, 2));
}
/**
* Determines if current color is different from given color
*
* @param AbstractColor $color
* @param integer $tolerance
* @return boolean
*/
public function differs(AbstractColor $color, $tolerance = 0)
{
$color_tolerance = round($tolerance * 2.55);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Saves a backups of current state of image core
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
// clone current image resource

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class BlurCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies blur effect on image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$amount = $this->argument(0)->between(0, 100)->value(1);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Changes image brightness
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$level = $this->argument(0)->between(-100, 100)->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Changes balance of different RGB color channels
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$red = $this->argument(0)->between(-100, 100)->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class ContrastCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Changes contrast of image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$level = $this->argument(0)->between(-100, 100)->required()->value();

View File

@@ -7,6 +7,12 @@ use \Intervention\Image\Size;
class CropCommand extends ResizeCommand
{
/**
* Crop an image instance
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class DestroyCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Destroys current image core and frees up memory
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
return imagedestroy($image->getCore());

View File

@@ -7,6 +7,12 @@ use Intervention\Image\Gd\Color;
class FillCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Fills image with color or pattern
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$filling = $this->argument(0)->value();

View File

@@ -7,9 +7,15 @@ use \Intervention\Image\Size;
class FitCommand extends ResizeCommand
{
/**
* Crops and resized an image at the same time
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->value();
$width = $this->argument(0)->type('integer')->required()->value();
$height = $this->argument(1)->type('integer')->value($width);
// calculate size

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class FlipCommand extends ResizeCommand
{
/**
* Mirrors an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mode = $this->argument(0)->value('h');

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class GammaCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies gamma correction to a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$gamma = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Size;
class GetSizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Reads size of given image instance in pixels
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$this->setOutput(new Size(

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class GreyscaleCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Turns an image into a greyscale version
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
return imagefilter($image->getCore(), IMG_FILTER_GRAYSCALE);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class HeightenCommand extends ResizeCommand
{
/**
* Resize image proportionally to given height
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$height = $this->argument(0)->type('integer')->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class InsertCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Insert another image into given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$source = $this->argument(0)->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class InterlaceCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Toggles interlaced encoding mode
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mode = $this->argument(0)->type('bool')->value(true);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class InvertCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Inverts colors of an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
return imagefilter($image->getCore(), IMG_FILTER_NEGATE);

View File

@@ -6,6 +6,12 @@ use Intervention\Image\Gd\Color;
class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Reduces colors of a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$count = $this->argument(0)->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class MaskCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies an alpha mask to an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mask_source = $this->argument(0)->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class OpacityCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Defines opacity of an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$transparency = $this->argument(0)->between(0, 100)->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Gd\Color;
class PickColorCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Read color information from a certain position
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$x = $this->argument(0)->type('integer')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Gd\Color;
class PixelCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Draws one pixel to a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$color = $this->argument(0)->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class PixelateCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies a pixelation effect to a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$size = $this->argument(0)->type('integer')->value(10);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class ResetCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Resets given image to its backup state
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
if (is_resource($backup = $image->getBackup())) {

View File

@@ -7,6 +7,12 @@ use \Intervention\Image\Size;
class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Resizes image boundaries
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class ResizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Resizes image dimensions
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Gd\Color;
class RotateCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Rotates image counter clockwise
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$angle = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Color;
class TrimCommand extends ResizeCommand
{
/**
* Trims away parts of an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$base = $this->argument(0)->type('string')->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Gd\Commands;
class WidenCommand extends ResizeCommand
{
/**
* Resize image proportionally to given width
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->required()->value();

View File

@@ -6,15 +6,26 @@ use \Intervention\Image\Size;
class Driver extends \Intervention\Image\AbstractDriver
{
public $source;
public $encoder;
/**
* Creates new instance of driver
*
* @param Intervention\Image\Gd\Source $source
* @param Intervention\Image\Gd\Encoder $encoder
*/
public function __construct(Source $source = null, Encoder $encoder = null)
{
$this->source = $source ? $source : new Source;
$this->encoder = $encoder ? $encoder : new Encoder;
}
/**
* Creates new image instance
*
* @param integer $width
* @param integer $height
* @param string $background
* @return Intervention\Image\Image
*/
public function newImage($width, $height, $background = null)
{
// create empty resource
@@ -29,6 +40,12 @@ class Driver extends \Intervention\Image\AbstractDriver
return $image;
}
/**
* Reads given string into color object
*
* @param string $value
* @return AbstractColor
*/
public function parseColor($value)
{
return new Color($value);

View File

@@ -4,6 +4,11 @@ namespace Intervention\Image\Gd;
class Encoder extends \Intervention\Image\AbstractEncoder
{
/**
* Processes and returns encoded image as JPEG string
*
* @return string
*/
protected function processJpeg()
{
ob_start();
@@ -15,6 +20,11 @@ class Encoder extends \Intervention\Image\AbstractEncoder
return $buffer;
}
/**
* Processes and returns encoded image as PNG string
*
* @return string
*/
protected function processPng()
{
ob_start();
@@ -29,6 +39,11 @@ class Encoder extends \Intervention\Image\AbstractEncoder
return $buffer;
}
/**
* Processes and returns encoded image as GIF string
*
* @return string
*/
protected function processGif()
{
ob_start();

View File

@@ -171,6 +171,7 @@ class Font extends \Intervention\Image\AbstractFont
/**
* Draws font to given image at given position
*
* @param Image $image
* @param integer $posx
* @param integer $posy

View File

@@ -6,8 +6,18 @@ use \Intervention\Image\Image;
class CircleShape extends EllipseShape
{
/**
* Radius of circle in pixels
*
* @var integer
*/
public $radius = 100;
/**
* Create new instance of circle
*
* @param integer $radius
*/
function __construct($radius = null)
{
$this->width = is_numeric($radius) ? intval($radius) : $this->radius;
@@ -15,6 +25,14 @@ class CircleShape extends EllipseShape
$this->radius = is_numeric($radius) ? intval($radius) : $this->radius;
}
/**
* Draw current circle on given image
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
return parent::applyToImage($image, $x, $y);

View File

@@ -7,15 +7,40 @@ use \Intervention\Image\Gd\Color;
class EllipseShape extends \Intervention\Image\AbstractShape
{
/**
* Width of ellipse in pixels
*
* @var integer
*/
public $width = 100;
/**
* Height of ellipse in pixels
*
* @var integer
*/
public $height = 100;
/**
* Create new ellipse instance
*
* @param integer $width
* @param integer $height
*/
function __construct($width = null, $height = null)
{
$this->width = is_numeric($width) ? intval($width) : $this->width;
$this->height = is_numeric($height) ? intval($height) : $this->height;
}
/**
* Draw ellipse instance on given image
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$background = new Color($this->background);

View File

@@ -7,22 +7,63 @@ use \Intervention\Image\Gd\Color;
class LineShape extends \Intervention\Image\AbstractShape
{
/**
* Starting point x-coordinate of line
*
* @var integer
*/
public $x = 0;
/**
* Starting point y-coordinate of line
*
* @var integer
*/
public $y = 0;
/**
* Color of line
*
* @var string
*/
public $color = '#000000';
/**
* Width of line in pixels
*
* @var integer
*/
public $width = 1;
/**
* Create new line shape instance
*
* @param integer $x
* @param integer $y
*/
function __construct($x = null, $y = null)
{
$this->x = is_numeric($x) ? intval($x) : $this->x;
$this->y = is_numeric($y) ? intval($y) : $this->y;
}
/**
* Set current line color
*
* @param string $color
* @return void
*/
public function color($color)
{
$this->color = $color;
}
/**
* Set current line width in pixels
*
* @param integer $width
* @return void
*/
public function width($width)
{
throw new \Intervention\Image\Exception\NotSupportedException(
@@ -30,6 +71,14 @@ class LineShape extends \Intervention\Image\AbstractShape
);
}
/**
* Draw current instance of line to given endpoint on given image
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$color = new Color($this->color);

View File

@@ -7,11 +7,42 @@ use \Intervention\Image\Gd\Color;
class RectangleShape extends \Intervention\Image\AbstractShape
{
/**
* X-Coordinate of top-left point
*
* @var integer
*/
public $x1 = 0;
/**
* Y-Coordinate of top-left point
*
* @var integer
*/
public $y1 = 0;
/**
* X-Coordinate of bottom-right point
*
* @var integer
*/
public $x2 = 0;
/**
* Y-Coordinate of bottom-right point
*
* @var integer
*/
public $y2 = 0;
/**
* Create new rectangle shape instance
*
* @param integer $x1
* @param integer $y1
* @param integer $x2
* @param integer $y2
*/
function __construct($x1 = null, $y1 = null, $x2 = null, $y2 = null)
{
$this->x1 = is_numeric($x1) ? intval($x1) : $this->x1;
@@ -20,6 +51,14 @@ class RectangleShape extends \Intervention\Image\AbstractShape
$this->y2 = is_numeric($y2) ? intval($y2) : $this->y2;
}
/**
* Draw rectangle to given image at certain position
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$background = new Color($this->background);

View File

@@ -7,6 +7,12 @@ use \Intervention\Image\Size;
class Source extends \Intervention\Image\AbstractSource
{
/**
* Initiates new image from path in filesystem
*
* @param string $path
* @return Intervention\Image\Image
*/
public function initFromPath($path)
{
$info = @getimagesize($path);
@@ -50,18 +56,36 @@ class Source extends \Intervention\Image\AbstractSource
return $image;
}
/**
* Initiates new image from GD resource
*
* @param Resource $resource
* @return Intervention\Image\Image
*/
public function initFromGdResource($resource)
{
return new Image(new Driver, $resource);
}
public function initFromImagick($object)
/**
* Initiates new image from Imagick object
*
* @param Imagick $object
* @return Intervention\Image\Image
*/
public function initFromImagick(\Imagick $object)
{
throw new \Intervention\Image\Exception\NotSupportedException(
"Gd driver is unable to init from Imagick object."
);
}
/**
* Initiates new image from binary data
*
* @param string $data
* @return Intervention\Image\Image
*/
public function initFromBinary($binary)
{
$resource = @imagecreatefromstring($binary);

View File

@@ -4,28 +4,79 @@ namespace Intervention\Image;
class Image extends File
{
/**
* Instance of current image driver
*
* @var Intervention\Image\AbstractDriver
*/
protected $driver;
/**
* Image resource/object of current image processor
*
* @var mixed
*/
protected $core;
/**
* Image resource backup of current image processor
*
* @var mixded
*/
protected $backup;
/**
* Last image encoding result
*
* @var string
*/
public $encoded = '';
/**
* Creates a new Image instance
*
* @param Driver $driver
* @param mixed $core
*/
public function __construct($driver = null, $core = null)
{
$this->driver = $driver;
$this->core = $core;
}
/**
* Magic method to catch all image calls
* usually any AbstractCommand
*
* @param string $name
* @param Array $arguments
* @return mixed
*/
public function __call($name, $arguments)
{
$command = $this->driver->executeCommand($this, $name, $arguments);
return $command->hasOutput() ? $command->getOutput() : $this;
}
/**
* Starts encoding of current image
*
* @param string $format
* @param integer $quality
* @return Intervention\Image\Image
*/
public function encode($format = null, $quality = 90)
{
return $this->driver->encode($this, $format, $quality);
}
/**
* Saves encoded image in filesystem
*
* @param string $path
* @param integer $quality
* @return Intervention\Image\Image
*/
public function save($path = null, $quality = null)
{
$path = is_null($path) ? ($this->dirname .'/'. $this->basename) : $path;
@@ -44,28 +95,53 @@ class Image extends File
return $this;
}
/**
* Runs a given filter on current image
*
* @param FiltersFilterInterface $filter
* @return Intervention\Image\Image
*/
public function filter(Filters\FilterInterface $filter)
{
return $filter->applyFilter($this);
}
/**
* Returns current image driver
*
* @return Intervention\Image\AbstractDriver
*/
public function getDriver()
{
return $this->driver;
}
public function setDriver($driver)
/**
* Sets current image driver
* @param AbstractDriver $driver
*/
public function setDriver(AbstractDriver $driver)
{
$this->driver = $driver;
return $this;
}
/**
* Returns current image resource/obj
*
* @return mixed
*/
public function getCore()
{
return $this->core;
}
/**
* Sets current image resource
*
* @param mixed $core
*/
public function setCore($core)
{
$this->core = $core;
@@ -73,11 +149,21 @@ class Image extends File
return $this;
}
/**
* Returns current image backup
*
* @return mixed
*/
public function getBackup()
{
return $this->backup;
}
/**
* Sets current image backup
*
* @param mixed $value
*/
public function setBackup($value)
{
$this->backup = $value;
@@ -85,16 +171,31 @@ class Image extends File
return $this;
}
/**
* Checks if current image is already encoded
*
* @return boolean
*/
public function isEncoded()
{
return ! is_null($this->encoded);
}
/**
* Returns encoded image data of current image
*
* @return string
*/
public function getEncoded()
{
return $this->encoded;
}
/**
* Sets encoded image buffer
*
* @param string $value
*/
public function setEncoded($value)
{
$this->encoded = $value;
@@ -102,16 +203,31 @@ class Image extends File
return $this;
}
/**
* Calculates current image width
*
* @return integer
*/
public function getWidth()
{
return $this->getSize()->width;
}
/**
* Calculates current image height
*
* @return integer
*/
public function getHeight()
{
return $this->getSize()->height;
}
/**
* Returns encoded image data in string conversion
*
* @return string
*/
public function __toString()
{
return $this->encoded;

View File

@@ -8,8 +8,18 @@ use Illuminate\Filesystem\Filesystem;
class ImageManager
{
/**
* Instance of Illuminate Config respository
*
* @var Illuminate\Config\Repository
*/
public $config;
/**
* Creates new instance of Image Manager
*
* @param Illuminate\Config\Repository $config
*/
public function __construct(\Illuminate\Config\Repository $config = null)
{
// create configurator
@@ -29,6 +39,11 @@ class ImageManager
}
}
/**
* Creates a driver instance according to config settings
*
* @return Intervention\Image\AbstractDriver
*/
private function createDriver()
{
$drivername = ucfirst($this->config->get('image::driver'));
@@ -43,11 +58,25 @@ class ImageManager
);
}
/**
* Initiates an Image instance from different input types
*
* @param mixed $data
* @return Intervention\Image\Image
*/
public function make($data)
{
return $this->createDriver()->init($data);
}
/**
* Creates an empty image canvas
*
* @param integer $width
* @param integer $height
* @param mixed $background
* @return Intervention\Image\Image
*/
public function canvas($width, $height, $background = null)
{
return $this->createDriver()->newImage($width, $height, $background);

View File

@@ -4,23 +4,52 @@ namespace Intervention\Image;
class ImageManagerStatic
{
/**
* Instance of Intervention\Image\ImageManager
*
* @var Intervention\Image\ImageManager
*/
public $manager;
/**
* Creates a new instance
*
* @param Intervention\Image\ImageManager $manager
*/
public function __construct(ImageManager $manager = null)
{
$this->manager = $manager ? $manager : new ImageManager;
}
/**
* Creates a new instance
*
* @return Intervention\Image\ImageManagerStatic
*/
public static function newInstance()
{
return new self;
}
/**
* Statically initiates an Image instance from different input types
*
* @param mixed $data
* @return Intervention\Image\Image
*/
public static function make($data)
{
return self::newInstance()->manager->make($data);
}
/**
* Statically creates an empty image canvas
*
* @param integer $width
* @param integer $height
* @param mixed $background
* @return Intervention\Image\Image
*/
public static function canvas($width, $height, $background = null)
{
return self::newInstance()->manager->canvas($width, $height, $background);

View File

@@ -4,8 +4,19 @@ namespace Intervention\Image\Imagick;
class Color extends \Intervention\Image\AbstractColor
{
/**
* ImagickPixel containing current color information
*
* @var ImagickPixel
*/
public $pixel;
/**
* Initiates color object from integer
*
* @param integer $value
* @return Intervention\Image\AbstractColor
*/
public function initFromInteger($value)
{
$a = ($value >> 24) & 0xFF;
@@ -17,6 +28,12 @@ class Color extends \Intervention\Image\AbstractColor
$this->setPixel($r, $g, $b, $a);
}
/**
* Initiates color object from given array
*
* @param array $value
* @return Intervention\Image\AbstractColor
*/
public function initFromArray($array)
{
$array = array_values($array);
@@ -36,6 +53,12 @@ class Color extends \Intervention\Image\AbstractColor
$this->setPixel($r, $g, $b, $a);
}
/**
* Initiates color object from given string
*
* @param string $value
* @return Intervention\Image\AbstractColor
*/
public function initFromString($value)
{
if ($color = $this->rgbaFromString($value)) {
@@ -43,6 +66,12 @@ class Color extends \Intervention\Image\AbstractColor
}
}
/**
* Initiates color object from given ImagickPixel object
*
* @param ImagickPixel $value
* @return Intervention\Image\AbstractColor
*/
public function initFromObject($value)
{
if (is_a($value, '\ImagickPixel')) {
@@ -50,16 +79,38 @@ class Color extends \Intervention\Image\AbstractColor
}
}
/**
* Initiates color object from given R, G and B values
*
* @param integer $r
* @param integer $g
* @param integer $b
* @return Intervention\Image\AbstractColor
*/
public function initFromRgb($r, $g, $b)
{
$this->setPixel($r, $g, $b);
}
/**
* Initiates color object from given R, G, B and A values
*
* @param integer $r
* @param integer $g
* @param integer $b
* @param float $a
* @return Intervention\Image\AbstractColor
*/
public function initFromRgba($r, $g, $b, $a)
{
$this->setPixel($r, $g, $b, $a);
}
/**
* Calculates integer value of current color instance
*
* @return integer
*/
public function getInt()
{
$r = $this->getRedValue();
@@ -70,6 +121,12 @@ class Color extends \Intervention\Image\AbstractColor
return intval(($a << 24) + ($r << 16) + ($g << 8) + $b);
}
/**
* Calculates hexadecimal value of current color instance
*
* @param string $prefix
* @return string
*/
public function getHex($prefix = '')
{
return sprintf('%s%02x%02x%02x', $prefix,
@@ -79,6 +136,11 @@ class Color extends \Intervention\Image\AbstractColor
);
}
/**
* Calculates RGB(A) in array format of current color instance
*
* @return array
*/
public function getArray()
{
return array(
@@ -89,6 +151,11 @@ class Color extends \Intervention\Image\AbstractColor
);
}
/**
* Calculates RGBA in string format of current color instance
*
* @return string
*/
public function getRgba()
{
return sprintf('rgba(%d, %d, %d, %.2f)',
@@ -99,6 +166,13 @@ class Color extends \Intervention\Image\AbstractColor
);
}
/**
* Determines if current color is different from given color
*
* @param AbstractColor $color
* @param integer $tolerance
* @return boolean
*/
public function differs(\Intervention\Image\AbstractColor $color, $tolerance = 0)
{
$color_tolerance = round($tolerance * 2.55);
@@ -119,26 +193,51 @@ class Color extends \Intervention\Image\AbstractColor
);
}
/**
* Returns RGB red value of current color
*
* @return integer
*/
public function getRedValue()
{
return intval(round($this->pixel->getColorValue(\Imagick::COLOR_RED) * 255));
}
/**
* Returns RGB green value of current color
*
* @return integer
*/
public function getGreenValue()
{
return intval(round($this->pixel->getColorValue(\Imagick::COLOR_GREEN) * 255));
}
/**
* Returns RGB blue value of current color
*
* @return integer
*/
public function getBlueValue()
{
return intval(round($this->pixel->getColorValue(\Imagick::COLOR_BLUE) * 255));
}
/**
* Returns RGB alpha value of current color
*
* @return float
*/
public function getAlphaValue()
{
return round($this->pixel->getColorValue(\Imagick::COLOR_ALPHA), 2);
}
/**
* Initiates ImagickPixel from given RGBA values
*
* @return ImagickPixel
*/
private function setPixel($r, $g, $b, $a = null)
{
$a = is_null($a) ? 1 : $a;
@@ -148,11 +247,22 @@ class Color extends \Intervention\Image\AbstractColor
);
}
/**
* Returns current color as ImagickPixel
*
* @return ImagickPixel
*/
public function getPixel()
{
return $this->pixel;
}
/**
* Calculates RGA integer alpha value into float value
*
* @param integer $value
* @return float
*/
private function rgb2alpha($value)
{
// (255 -> 1.0) / (0 -> 0.0)

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Saves a backups of current state of image core
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
// clone current image resource

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class BlurCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies blur effect on image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$amount = $this->argument(0)->between(0, 100)->value(1);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Changes image brightness
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$level = $this->argument(0)->between(-100, 100)->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Changes balance of different RGB color channels
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$red = $this->argument(0)->between(-100, 100)->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class ContrastCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Changes contrast of image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$level = $this->argument(0)->between(-100, 100)->required()->value();

View File

@@ -7,6 +7,12 @@ use \Intervention\Image\Size;
class CropCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Crop an image instance
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class DestroyCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Destroys current image core and frees up memory
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
return $image->getCore()->clear();

View File

@@ -8,6 +8,12 @@ use \Intervention\Image\Imagick\Color;
class FillCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Fills image with color or pattern
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$filling = $this->argument(0)->value();

View File

@@ -6,9 +6,15 @@ use \Intervention\Image\Size;
class FitCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Crops and resized an image at the same time
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->value();
$width = $this->argument(0)->type('integer')->required()->value();
$height = $this->argument(1)->type('integer')->value($width);
// calculate size

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class FlipCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Mirrors an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mode = $this->argument(0)->value('h');

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class GammaCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies gamma correction to a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$gamma = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Size;
class GetSizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Reads size of given image instance in pixels
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$info = $image->getCore()->identifyImage(true);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class GreyscaleCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Turns an image into a greyscale version
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
return $image->getCore()->modulateImage(100, 0, 100);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class HeightenCommand extends ResizeCommand
{
/**
* Resize image proportionally to given height
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$height = $this->argument(0)->type('integer')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Imagick\Source;
class InsertCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Insert another image into given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$source = $this->argument(0)->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class InterlaceCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Toggles interlaced encoding mode
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mode = $this->argument(0)->type('bool')->value(true);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class InvertCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Inverts colors of an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
return $image->getCore()->negateImage(false);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Reduces colors of a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$count = $this->argument(0)->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class MaskCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies an alpha mask to an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mask_source = $this->argument(0)->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class OpacityCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Defines opacity of an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$transparency = $this->argument(0)->between(0, 100)->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Imagick\Color;
class PickColorCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Read color information from a certain position
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$x = $this->argument(0)->type('integer')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Imagick\Color;
class PixelCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Draws one pixel to a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$color = $this->argument(0)->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class PixelateCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Applies a pixelation effect to a given image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$size = $this->argument(0)->type('integer')->value(10);

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class ResetCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Resets given image to its backup state
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$backup = $image->getBackup();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Resizes image boundaries
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->required()->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class ResizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Resizes image dimensions
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Imagick\Color;
class RotateCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Rotates image counter clockwise
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$angle = $this->argument(0)->type('numeric')->required()->value();

View File

@@ -6,6 +6,12 @@ use \Intervention\Image\Imagick\Color;
class TrimCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**
* Trims away parts of an image
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$base = $this->argument(0)->type('string')->value();

View File

@@ -4,6 +4,12 @@ namespace Intervention\Image\Imagick\Commands;
class WidenCommand extends ResizeCommand
{
/**
* Resize image proportionally to given width
*
* @param Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->type('integer')->required()->value();

View File

@@ -6,15 +6,26 @@ use \Intervention\Image\Size;
class Driver extends \Intervention\Image\AbstractDriver
{
public $source;
public $encoder;
/**
* Creates new instance of driver
*
* @param Intervention\Image\Imagick\Source $source
* @param Intervention\Image\Imagick\Encoder $encoder
*/
public function __construct(Source $source = null, Encoder $encoder = null)
{
$this->source = $source ? $source : new Source;
$this->encoder = $encoder ? $encoder : new Encoder;
}
/**
* Creates new image instance
*
* @param integer $width
* @param integer $height
* @param string $background
* @return Intervention\Image\Image
*/
public function newImage($width, $height, $background = null)
{
$background = new Color($background);
@@ -35,6 +46,12 @@ class Driver extends \Intervention\Image\AbstractDriver
return $image;
}
/**
* Reads given string into color object
*
* @param string $value
* @return AbstractColor
*/
public function parseColor($value)
{
return new Color($value);

View File

@@ -4,6 +4,11 @@ namespace Intervention\Image\Imagick;
class Encoder extends \Intervention\Image\AbstractEncoder
{
/**
* Processes and returns encoded image as JPEG string
*
* @return string
*/
protected function processJpeg()
{
$format = 'jpeg';
@@ -20,6 +25,11 @@ class Encoder extends \Intervention\Image\AbstractEncoder
return (string) $imagick;
}
/**
* Processes and returns encoded image as PNG string
*
* @return string
*/
protected function processPng()
{
$format = 'png';
@@ -34,6 +44,11 @@ class Encoder extends \Intervention\Image\AbstractEncoder
return (string) $imagick;
}
/**
* Processes and returns encoded image as GIF string
*
* @return string
*/
protected function processGif()
{
$format = 'gif';

View File

@@ -57,6 +57,7 @@ class Font extends \Intervention\Image\AbstractFont
/**
* Draws font to given image at given position
*
* @param Image $image
* @param integer $posx
* @param integer $posy

View File

@@ -6,8 +6,18 @@ use \Intervention\Image\Image;
class CircleShape extends EllipseShape
{
/**
* Radius of circle in pixels
*
* @var integer
*/
public $radius = 100;
/**
* Create new instance of circle
*
* @param integer $radius
*/
function __construct($radius = null)
{
$this->width = is_numeric($radius) ? intval($radius) : $this->radius;
@@ -15,6 +25,14 @@ class CircleShape extends EllipseShape
$this->radius = is_numeric($radius) ? intval($radius) : $this->radius;
}
/**
* Draw current circle on given image
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
return parent::applyToImage($image, $x, $y);

View File

@@ -7,15 +7,40 @@ use \Intervention\Image\Imagick\Color;
class EllipseShape extends \Intervention\Image\AbstractShape
{
/**
* Width of ellipse in pixels
*
* @var integer
*/
public $width = 100;
/**
* Height of ellipse in pixels
*
* @var integer
*/
public $height = 100;
/**
* Create new ellipse instance
*
* @param integer $width
* @param integer $height
*/
function __construct($width = null, $height = null)
{
$this->width = is_numeric($width) ? intval($width) : $this->width;
$this->height = is_numeric($height) ? intval($height) : $this->height;
}
/**
* Draw ellipse instance on given image
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$circle = new \ImagickDraw;

View File

@@ -7,27 +7,76 @@ use \Intervention\Image\Imagick\Color;
class LineShape extends \Intervention\Image\AbstractShape
{
/**
* Starting point x-coordinate of line
*
* @var integer
*/
public $x = 0;
/**
* Starting point y-coordinate of line
*
* @var integer
*/
public $y = 0;
/**
* Color of line
*
* @var string
*/
public $color = '#000000';
/**
* Width of line in pixels
*
* @var integer
*/
public $width = 1;
/**
* Create new line shape instance
*
* @param integer $x
* @param integer $y
*/
function __construct($x = null, $y = null)
{
$this->x = is_numeric($x) ? intval($x) : $this->x;
$this->y = is_numeric($y) ? intval($y) : $this->y;
}
/**
* Set current line color
*
* @param string $color
* @return void
*/
public function color($color)
{
$this->color = $color;
}
/**
* Set current line width in pixels
*
* @param integer $width
* @return void
*/
public function width($width)
{
$this->width = $width;
}
/**
* Draw current instance of line to given endpoint on given image
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$line = new \ImagickDraw;

View File

@@ -7,11 +7,42 @@ use \Intervention\Image\Imagick\Color;
class RectangleShape extends \Intervention\Image\AbstractShape
{
/**
* X-Coordinate of top-left point
*
* @var integer
*/
public $x1 = 0;
/**
* Y-Coordinate of top-left point
*
* @var integer
*/
public $y1 = 0;
/**
* X-Coordinate of bottom-right point
*
* @var integer
*/
public $x2 = 0;
/**
* Y-Coordinate of bottom-right point
*
* @var integer
*/
public $y2 = 0;
/**
* Create new rectangle shape instance
*
* @param integer $x1
* @param integer $y1
* @param integer $x2
* @param integer $y2
*/
function __construct($x1 = null, $y1 = null, $x2 = null, $y2 = null)
{
$this->x1 = is_numeric($x1) ? intval($x1) : $this->x1;
@@ -20,6 +51,14 @@ class RectangleShape extends \Intervention\Image\AbstractShape
$this->y2 = is_numeric($y2) ? intval($y2) : $this->y2;
}
/**
* Draw rectangle to given image at certain position
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$rectangle = new \ImagickDraw;

View File

@@ -7,6 +7,12 @@ use \Intervention\Image\Size;
class Source extends \Intervention\Image\AbstractSource
{
/**
* Initiates new image from path in filesystem
*
* @param string $path
* @return Intervention\Image\Image
*/
public function initFromPath($path)
{
$core = new \Imagick;
@@ -29,6 +35,12 @@ class Source extends \Intervention\Image\AbstractSource
return $image;
}
/**
* Initiates new image from GD resource
*
* @param Resource $resource
* @return Intervention\Image\Image
*/
public function initFromGdResource($resource)
{
throw new \Intervention\Image\Exception\NotSupportedException(
@@ -36,11 +48,23 @@ class Source extends \Intervention\Image\AbstractSource
);
}
public function initFromImagick($object)
/**
* Initiates new image from Imagick object
*
* @param Imagick $object
* @return Intervention\Image\Image
*/
public function initFromImagick(\Imagick $object)
{
return new Image(new Driver, $object);
}
/**
* Initiates new image from binary data
*
* @param string $data
* @return Intervention\Image\Image
*/
public function initFromBinary($binary)
{
$core = new \Imagick;

View File

@@ -4,25 +4,58 @@ namespace Intervention\Image;
class Point
{
/**
* X coordinate
*
* @var integer
*/
public $x;
/**
* Y coordinate
*
* @var integer
*/
public $y;
/**
* Creates a new instance
*
* @param integer $x
* @param integer $y
*/
public function __construct($x = null, $y = null)
{
$this->x = is_numeric($x) ? intval($x) : 0;
$this->y = is_numeric($y) ? intval($y) : 0;
}
/**
* Sets X coordinate
*
* @param integer $x
*/
public function setX($x)
{
$this->x = intval($x);
}
/**
* Sets Y coordinate
*
* @param integer $y
*/
public function setY($y)
{
$this->y = intval($y);
}
/**
* Sets both X and Y coordinate
*
* @param integer $x
* @param integer $y
*/
public function setPosition($x, $y)
{
$this->setX($x);

Some files were not shown because too many files have changed in this diff Show More