1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-07 14:26:31 +02:00

various minor fixes

This commit is contained in:
Oliver Vogel
2014-06-30 17:30:03 +02:00
parent 25aba89310
commit fc0c202772
17 changed files with 111 additions and 149 deletions

View File

@@ -139,7 +139,6 @@ abstract class AbstractColor
throw new \Intervention\Image\Exception\NotReadableException( throw new \Intervention\Image\Exception\NotReadableException(
"Color format ({$value}) cannot be read." "Color format ({$value}) cannot be read."
); );
break;
} }
return $this; return $this;
@@ -157,31 +156,25 @@ abstract class AbstractColor
case 'rgba': case 'rgba':
return $this->getRgba(); return $this->getRgba();
break;
case 'hex': case 'hex':
return $this->getHex('#'); return $this->getHex('#');
break;
case 'int': case 'int':
case 'integer': case 'integer':
return $this->getInt(); return $this->getInt();
break;
case 'array': case 'array':
return $this->getArray(); return $this->getArray();
break;
case 'obj': case 'obj':
case 'object': case 'object':
return $this; return $this;
break;
default: default:
throw new \Intervention\Image\Exception\NotSupportedException( throw new \Intervention\Image\Exception\NotSupportedException(
"Color format ({$type}) is not supported." "Color format ({$type}) is not supported."
); );
break;
} }
} }

View File

@@ -161,35 +161,27 @@ abstract class AbstractDecoder
case $this->isGdResource(): case $this->isGdResource():
return $this->initFromGdResource($this->data); return $this->initFromGdResource($this->data);
break;
case $this->isImagick(): case $this->isImagick():
return $this->initFromImagick($this->data); return $this->initFromImagick($this->data);
break;
case $this->isInterventionImage(): case $this->isInterventionImage():
return $this->initFromInterventionImage($this->data); return $this->initFromInterventionImage($this->data);
break;
case $this->isSymfonyUpload(): case $this->isSymfonyUpload():
return $this->initFromPath($this->data->getRealPath()); return $this->initFromPath($this->data->getRealPath());
break;
case $this->isBinary(): case $this->isBinary():
return $this->initFromBinary($this->data); return $this->initFromBinary($this->data);
break;
case $this->isUrl(): case $this->isUrl():
return $this->initFromBinary(file_get_contents($this->data)); return $this->initFromBinary(file_get_contents($this->data));
break;
case $this->isFilePath(): case $this->isFilePath():
return $this->initFromPath($this->data); return $this->initFromPath($this->data);
break;
default: default:
throw new Exception\NotReadableException("Image source not readable"); throw new Exception\NotReadableException("Image source not readable");
break;
} }
} }

View File

@@ -4,6 +4,34 @@ namespace Intervention\Image;
abstract class AbstractEncoder abstract class AbstractEncoder
{ {
/**
* Buffer of encode result data
*
* @var string
*/
public $result;
/**
* Image object to encode
*
* @var Image
*/
public $image;
/**
* Output format of encoder instance
*
* @var string
*/
public $format;
/**
* Output quality of encoder instance
*
* @var integer
*/
public $quality;
/** /**
* Processes and returns encoded image as JPEG string * Processes and returns encoded image as JPEG string
* *
@@ -32,20 +60,13 @@ abstract class AbstractEncoder
*/ */
abstract protected function processTiff(); abstract protected function processTiff();
/**
* Buffer of encode result data
*
* @var string
*/
public $result;
/** /**
* Process a given image * Process a given image
* *
* @param Image $image * @param Image $image
* @param string $format * @param string $format
* @param integer $quality * @param integer $quality
* @return Intervention\Image\Image * @return Image
*/ */
public function process(Image $image, $format = null, $quality = null) public function process(Image $image, $format = null, $quality = null)
{ {
@@ -86,7 +107,6 @@ abstract class AbstractEncoder
throw new \Intervention\Image\Exception\NotSupportedException( throw new \Intervention\Image\Exception\NotSupportedException(
"Encoding format ({$format}) is not supported." "Encoding format ({$format}) is not supported."
); );
break;
} }
return $image->setEncoded($this->result); return $image->setEncoded($this->result);
@@ -108,7 +128,7 @@ abstract class AbstractEncoder
/** /**
* Sets image to process * Sets image to process
* *
* @param Intervention\Image\Image $image * @param Image $image
*/ */
protected function setImage($image) protected function setImage($image)
{ {

View File

@@ -4,6 +4,55 @@ namespace Intervention\Image;
abstract class AbstractFont abstract class AbstractFont
{ {
/**
* Text to be written
*
* @var String
*/
public $text;
/**
* Text size in pixels
*
* @var integer
*/
public $size = 12;
/**
* Color of the text
*
* @var mixed
*/
public $color = '000000';
/**
* Rotation angle of the text
*
* @var integer
*/
public $angle = 0;
/**
* Horizontal alignment of the text
*
* @var String
*/
public $align;
/**
* Vertical alignment of the text
*
* @var String
*/
public $valign;
/**
* Path to TTF or GD library internal font file of the text
*
* @var mixed
*/
public $file;
/** /**
* Draws font to given image on given position * Draws font to given image on given position
* *

View File

@@ -7,7 +7,7 @@ class Argument
/** /**
* Command with arguments * Command with arguments
* *
* @var Intervention\Image\Commands\AbstractCommand * @var AbstractCommand
*/ */
public $command; public $command;

View File

@@ -43,9 +43,8 @@ class Decoder extends \Intervention\Image\AbstractDecoder
default: default:
throw new \Intervention\Image\Exception\NotReadableException( throw new \Intervention\Image\Exception\NotReadableException(
"Unable to read image type ({$this->type}) only use JPG, PNG or GIF images with GD driver." "Unable to read image type. Only use JPG, PNG or GIF images with GD driver."
); );
break;
} }
// build image // build image

View File

@@ -9,8 +9,8 @@ class Driver extends \Intervention\Image\AbstractDriver
/** /**
* Creates new instance of driver * Creates new instance of driver
* *
* @param Intervention\Image\Gd\Decoder $decoder * @param Decoder $decoder
* @param Intervention\Image\Gd\Encoder $encoder * @param Encoder $encoder
*/ */
public function __construct(Decoder $decoder = null, Encoder $encoder = null) public function __construct(Decoder $decoder = null, Encoder $encoder = null)
{ {
@@ -36,8 +36,7 @@ class Driver extends \Intervention\Image\AbstractDriver
{ {
// create empty resource // create empty resource
$core = imagecreatetruecolor($width, $height); $core = imagecreatetruecolor($width, $height);
$size = new Size($width, $height); $image = new \Intervention\Image\Image(new self, $core);
$image = new \Intervention\Image\Image(new self, $core, $size);
// set background color // set background color
$background = new Color($background); $background = new Color($background);

View File

@@ -6,55 +6,6 @@ use \Intervention\Image\Image;
class Font extends \Intervention\Image\AbstractFont class Font extends \Intervention\Image\AbstractFont
{ {
/**
* Text to be written
*
* @var String
*/
protected $text;
/**
* Text size in pixels
*
* @var integer
*/
protected $size = 12;
/**
* Color of the text
*
* @var mixed
*/
protected $color = '000000';
/**
* Rotation angle of the text
*
* @var integer
*/
protected $angle = 0;
/**
* Horizontal alignment of the text
*
* @var String
*/
protected $align;
/**
* Vertical alignment of the text
*
* @var String
*/
protected $valign;
/**
* Path to TTF or GD library internal font file of the text
*
* @var mixed
*/
protected $file;
/** /**
* Get font size in points * Get font size in points
* *

View File

@@ -7,7 +7,7 @@ class Image extends File
/** /**
* Instance of current image driver * Instance of current image driver
* *
* @var Intervention\Image\AbstractDriver * @var AbstractDriver
*/ */
protected $driver; protected $driver;
@@ -21,7 +21,7 @@ class Image extends File
/** /**
* Image resource backup of current image processor * Image resource backup of current image processor
* *
* @var mixded * @var mixed
*/ */
protected $backup; protected $backup;
@@ -35,7 +35,7 @@ class Image extends File
/** /**
* Creates a new Image instance * Creates a new Image instance
* *
* @param Driver $driver * @param AbstractDriver $driver
* @param mixed $core * @param mixed $core
*/ */
public function __construct(AbstractDriver $driver = null, $core = null) public function __construct(AbstractDriver $driver = null, $core = null)

View File

@@ -12,14 +12,14 @@ class ImageManager
/** /**
* Instance of Illuminate Config respository * Instance of Illuminate Config respository
* *
* @var Illuminate\Config\Repository * @var \Illuminate\Config\Repository
*/ */
public $config; public $config;
/** /**
* Creates new instance of Image Manager * Creates new instance of Image Manager
* *
* @param Illuminate\Config\Repository $config * @param \Illuminate\Config\Repository $config
*/ */
public function __construct(\Illuminate\Config\Repository $config = null) public function __construct(\Illuminate\Config\Repository $config = null)
{ {
@@ -63,6 +63,7 @@ class ImageManager
* Initiates an Image instance from different input types * Initiates an Image instance from different input types
* *
* @param mixed $data * @param mixed $data
*
* @return Intervention\Image\Image * @return Intervention\Image\Image
*/ */
public function make($data) public function make($data)
@@ -76,6 +77,7 @@ class ImageManager
* @param integer $width * @param integer $width
* @param integer $height * @param integer $height
* @param mixed $background * @param mixed $background
*
* @return Intervention\Image\Image * @return Intervention\Image\Image
*/ */
public function canvas($width, $height, $background = null) public function canvas($width, $height, $background = null)

View File

@@ -9,14 +9,14 @@ class ImageManagerStatic
/** /**
* Instance of Intervention\Image\ImageManager * Instance of Intervention\Image\ImageManager
* *
* @var Intervention\Image\ImageManager * @var ImageManager
*/ */
public $manager; public $manager;
/** /**
* Creates a new instance * Creates a new instance
* *
* @param Intervention\Image\ImageManager $manager * @param ImageManager $manager
*/ */
public function __construct(ImageManager $manager = null) public function __construct(ImageManager $manager = null)
{ {
@@ -37,6 +37,7 @@ class ImageManagerStatic
* Statically initiates an Image instance from different input types * Statically initiates an Image instance from different input types
* *
* @param mixed $data * @param mixed $data
*
* @return Intervention\Image\Image * @return Intervention\Image\Image
*/ */
public static function make($data) public static function make($data)
@@ -50,6 +51,7 @@ class ImageManagerStatic
* @param integer $width * @param integer $width
* @param integer $height * @param integer $height
* @param mixed $background * @param mixed $background
*
* @return Intervention\Image\Image * @return Intervention\Image\Image
*/ */
public static function canvas($width, $height, $background = null) public static function canvas($width, $height, $background = null)
@@ -63,6 +65,7 @@ class ImageManagerStatic
* @param Closure $callback * @param Closure $callback
* @param integer $lifetime * @param integer $lifetime
* @param boolean $returnObj * @param boolean $returnObj
*
* @return mixed * @return mixed
*/ */
public static function cache(Closure $callback, $lifetime = null, $returnObj = false) public static function cache(Closure $callback, $lifetime = null, $returnObj = false)

View File

@@ -1,7 +1,7 @@
<?php namespace Intervention\Image; <?php namespace Intervention\Image;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Response; use Illuminate\Http\Response as IlluminateResponse;
class ImageServiceProvider extends ServiceProvider class ImageServiceProvider extends ServiceProvider
{ {
@@ -89,7 +89,7 @@ class ImageServiceProvider extends ServiceProvider
$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content); $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
// return http response // return http response
return new Response($content, 200, array( return new IlluminateResponse($content, 200, array(
'Content-Type' => $mime, 'Content-Type' => $mime,
'Cache-Control' => 'max-age='.($config->get('imagecache::lifetime')*60).', public', 'Cache-Control' => 'max-age='.($config->get('imagecache::lifetime')*60).', public',
'Etag' => md5($content) 'Etag' => md5($content)

View File

@@ -7,7 +7,7 @@ class Color extends \Intervention\Image\AbstractColor
/** /**
* ImagickPixel containing current color information * ImagickPixel containing current color information
* *
* @var ImagickPixel * @var \ImagickPixel
*/ */
public $pixel; public $pixel;
@@ -57,6 +57,7 @@ class Color extends \Intervention\Image\AbstractColor
* Initiates color object from given string * Initiates color object from given string
* *
* @param string $value * @param string $value
*
* @return Intervention\Image\AbstractColor * @return Intervention\Image\AbstractColor
*/ */
public function initFromString($value) public function initFromString($value)
@@ -70,6 +71,7 @@ class Color extends \Intervention\Image\AbstractColor
* Initiates color object from given ImagickPixel object * Initiates color object from given ImagickPixel object
* *
* @param ImagickPixel $value * @param ImagickPixel $value
*
* @return Intervention\Image\AbstractColor * @return Intervention\Image\AbstractColor
*/ */
public function initFromObject($value) public function initFromObject($value)
@@ -85,6 +87,7 @@ class Color extends \Intervention\Image\AbstractColor
* @param integer $r * @param integer $r
* @param integer $g * @param integer $g
* @param integer $b * @param integer $b
*
* @return Intervention\Image\AbstractColor * @return Intervention\Image\AbstractColor
*/ */
public function initFromRgb($r, $g, $b) public function initFromRgb($r, $g, $b)
@@ -99,6 +102,7 @@ class Color extends \Intervention\Image\AbstractColor
* @param integer $g * @param integer $g
* @param integer $b * @param integer $b
* @param float $a * @param float $a
*
* @return Intervention\Image\AbstractColor * @return Intervention\Image\AbstractColor
*/ */
public function initFromRgba($r, $g, $b, $a) public function initFromRgba($r, $g, $b, $a)
@@ -125,6 +129,7 @@ class Color extends \Intervention\Image\AbstractColor
* Calculates hexadecimal value of current color instance * Calculates hexadecimal value of current color instance
* *
* @param string $prefix * @param string $prefix
*
* @return string * @return string
*/ */
public function getHex($prefix = '') public function getHex($prefix = '')
@@ -236,7 +241,7 @@ class Color extends \Intervention\Image\AbstractColor
/** /**
* Initiates ImagickPixel from given RGBA values * Initiates ImagickPixel from given RGBA values
* *
* @return ImagickPixel * @return \ImagickPixel
*/ */
private function setPixel($r, $g, $b, $a = null) private function setPixel($r, $g, $b, $a = null)
{ {
@@ -250,7 +255,7 @@ class Color extends \Intervention\Image\AbstractColor
/** /**
* Returns current color as ImagickPixel * Returns current color as ImagickPixel
* *
* @return ImagickPixel * @return \ImagickPixel
*/ */
public function getPixel() public function getPixel()
{ {

View File

@@ -9,8 +9,8 @@ class Driver extends \Intervention\Image\AbstractDriver
/** /**
* Creates new instance of driver * Creates new instance of driver
* *
* @param Intervention\Image\Imagick\Decoder $decoder * @param Decoder $decoder
* @param Intervention\Image\Imagick\Encoder $encoder * @param Encoder $encoder
*/ */
public function __construct(Decoder $decoder = null, Encoder $encoder = null) public function __construct(Decoder $decoder = null, Encoder $encoder = null)
{ {
@@ -44,10 +44,8 @@ class Driver extends \Intervention\Image\AbstractDriver
$core->setColorspace(\Imagick::COLORSPACE_UNDEFINED); $core->setColorspace(\Imagick::COLORSPACE_UNDEFINED);
$core->setImageColorspace(\Imagick::COLORSPACE_UNDEFINED); $core->setImageColorspace(\Imagick::COLORSPACE_UNDEFINED);
$size = new Size($width, $height);
// build image // build image
$image = new \Intervention\Image\Image(new self, $core, $size); $image = new \Intervention\Image\Image(new self, $core);
return $image; return $image;
} }

View File

@@ -6,55 +6,6 @@ use \Intervention\Image\Image;
class Font extends \Intervention\Image\AbstractFont class Font extends \Intervention\Image\AbstractFont
{ {
/**
* Text to be written
*
* @var String
*/
protected $text;
/**
* Text size in pixels
*
* @var integer
*/
protected $size = 12;
/**
* Color of the text
*
* @var mixed
*/
protected $color = '000000';
/**
* Rotation angle of the text
*
* @var integer
*/
protected $angle = 0;
/**
* Horizontal alignment of the text
*
* @var String
*/
protected $align;
/**
* Vertical alignment of the text
*
* @var String
*/
protected $valign;
/**
* Path to TTF or GD library internal font file of the text
*
* @var mixed
*/
protected $file;
/** /**
* Draws font to given image at given position * Draws font to given image at given position
* *

View File

@@ -7,7 +7,7 @@ class Response
/** /**
* Image that should be displayed by response * Image that should be displayed by response
* *
* @var Intervention\Image\Image * @var Image
*/ */
public $image; public $image;

View File

@@ -23,7 +23,7 @@ class Size
/** /**
* Pivot point * Pivot point
* *
* @var Intervention\Image\Point * @var Point
*/ */
public $pivot; public $pivot;