1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 02:12:37 +02:00

psr2 fixes

This commit is contained in:
Oliver Vogel
2013-02-15 20:01:53 +01:00
parent 27bbfb0c1b
commit bac53270b0
5 changed files with 193 additions and 191 deletions

View File

@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false" <phpunit backupGlobals="false"
backupStaticAttributes="false" backupStaticAttributes="false"
bootstrap="vendor/autoload.php" bootstrap="vendor/autoload.php"
colors="true" colors="true"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
syntaxCheck="false" syntaxCheck="false"
> >
<testsuites> <testsuites>
<testsuite name="Package Test Suite"> <testsuite name="Package Test Suite">
<directory>./tests/</directory> <directory>./tests/</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
</phpunit> </phpunit>

View File

@@ -10,4 +10,4 @@ class Image extends Facade
{ {
return 'image'; return 'image';
} }
} }

View File

@@ -30,7 +30,7 @@ class Image
* @var integer * @var integer
*/ */
public $height; public $height;
/** /**
* Directory path of current image * Directory path of current image
* @var string * @var string
@@ -60,13 +60,13 @@ class Image
* @var Filesystem * @var Filesystem
*/ */
protected $filesystem; protected $filesystem;
/** /**
* Create a new instance of Image class * Create a new instance of Image class
* *
* @param string $path * @param string $path
*/ */
public function __construct($path = null, $width = null, $height = null) public function __construct($path = null, $width = null, $height = null)
{ {
$this->filesystem = new Filesystem; $this->filesystem = new Filesystem;
$this->setProperties($path, $width, $height); $this->setProperties($path, $width, $height);
@@ -74,7 +74,7 @@ class Image
/** /**
* Open a new image resource from image file or create a new empty image * Open a new image resource from image file or create a new empty image
* *
* @param string $path * @param string $path
* @return Image * @return Image
*/ */
@@ -85,7 +85,7 @@ class Image
/** /**
* Create a new empty image resource * Create a new empty image resource
* *
* @param int $width * @param int $width
* @param int $height * @param int $height
* @return Image * @return Image
@@ -97,13 +97,13 @@ class Image
/** /**
* Set local properties for image resource * Set local properties for image resource
* *
* @param string $path * @param string $path
*/ */
private function setProperties($path, $width = null, $height = null) private function setProperties($path, $width = null, $height = null)
{ {
if ( ! is_null($path)) { if ( ! is_null($path)) {
if (!$this->filesystem->exists($path)) { if (!$this->filesystem->exists($path)) {
throw new Exception("Image file ({$path}) not found"); throw new Exception("Image file ({$path}) not found");
} }
@@ -124,7 +124,7 @@ class Image
case 3: case 3:
$this->resource = @imagecreatefrompng($path); $this->resource = @imagecreatefrompng($path);
break; break;
case IMG_JPG: case IMG_JPG:
$this->resource = @imagecreatefromjpeg($path); $this->resource = @imagecreatefromjpeg($path);
break; break;
@@ -139,7 +139,7 @@ class Image
} }
} else { } else {
$this->width = is_numeric($width) ? intval($width) : 1; $this->width = is_numeric($width) ? intval($width) : 1;
$this->height = is_numeric($height) ? intval($height) : 1; $this->height = is_numeric($height) ? intval($height) : 1;
@@ -151,10 +151,10 @@ class Image
imagefill($this->resource, 0, 0, $transparent); imagefill($this->resource, 0, 0, $transparent);
} }
} }
/** /**
* Modify wrapper function used by resize and grab * Modify wrapper function used by resize and grab
* *
* @param integer $dst_x * @param integer $dst_x
* @param integer $dst_y * @param integer $dst_y
* @param integer $src_x * @param integer $src_x
@@ -170,7 +170,7 @@ class Image
// create new image // create new image
$image = @imagecreatetruecolor($dst_w, $dst_h); $image = @imagecreatetruecolor($dst_w, $dst_h);
// copy content from resource // copy content from resource
@imagecopyresampled($image, $this->resource, $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h); @imagecopyresampled($image, $this->resource, $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h);
// set new content as recource // set new content as recource
@@ -185,22 +185,22 @@ class Image
/** /**
* Resize current image based on given width/height * Resize current image based on given width/height
* *
* @param mixed width|height width and height are optional, the not given * @param mixed width|height width and height are optional, the not given
* parameter is calculated based on the given * parameter is calculated based on the given
* @return Image * @return Image
*/ */
public function resize() public function resize()
{ {
$args = func_get_args(); $args = func_get_args();
if (array_key_exists(0, $args) && is_array($args[0])) { if (array_key_exists(0, $args) && is_array($args[0])) {
// extract 'width' and 'height' // extract 'width' and 'height'
extract(array_only($args[0], array('width', 'height'))); extract(array_only($args[0], array('width', 'height')));
$width = isset($width) ? intval($width) : null; $width = isset($width) ? intval($width) : null;
$height = isset($height) ? intval($height) : null; $height = isset($height) ? intval($height) : null;
if ( ! is_null($width) OR ! is_null($height)) { if ( ! is_null($width) OR ! is_null($height)) {
// if width or height are not set, define values automatically // if width or height are not set, define values automatically
$width = is_null($width) ? intval($height / $this->height * $this->width) : $width; $width = is_null($width) ? intval($height / $this->height * $this->width) : $width;
@@ -225,7 +225,7 @@ class Image
/** /**
* Cut out a detail of the image in given ratio and resize to output size * Cut out a detail of the image in given ratio and resize to output size
* *
* @param mixed width|height width and height are optional, the not given * @param mixed width|height width and height are optional, the not given
* parameter is calculated based on the given * parameter is calculated based on the given
* @return Image * @return Image
@@ -235,11 +235,11 @@ class Image
$args = func_get_args(); $args = func_get_args();
if (array_key_exists(0, $args) && is_array($args[0])) { if (array_key_exists(0, $args) && is_array($args[0])) {
// extract 'width' and 'height' // extract 'width' and 'height'
extract(array_only($args[0], array('width', 'height'))); extract(array_only($args[0], array('width', 'height')));
$width = isset($width) ? intval($width) : null; $width = isset($width) ? intval($width) : null;
$height = isset($height) ? intval($height) : null; $height = isset($height) ? intval($height) : null;
if ( ! is_null($width) OR ! is_null($height)) { if ( ! is_null($width) OR ! is_null($height)) {
// if width or height are not set, define values automatically // if width or height are not set, define values automatically
$width = is_null($width) ? $height : $width; $width = is_null($width) ? $height : $width;
@@ -250,12 +250,12 @@ class Image
} }
} elseif (array_key_exists(0, $args) && array_key_exists(1, $args) && is_numeric($args[0]) && is_numeric($args[1])) { } elseif (array_key_exists(0, $args) && array_key_exists(1, $args) && is_numeric($args[0]) && is_numeric($args[1])) {
$width = intval($args[0]); $width = intval($args[0]);
$height = intval($args[1]); $height = intval($args[1]);
} elseif (array_key_exists(0, $args) && is_numeric($args[0])) { } elseif (array_key_exists(0, $args) && is_numeric($args[0])) {
$width = intval($args[0]); $width = intval($args[0]);
$height = intval($args[0]); $height = intval($args[0]);
@@ -286,7 +286,7 @@ class Image
/** /**
* Insert another image on top of the current image * Insert another image on top of the current image
* *
* @param string $file * @param string $file
* @param integer $pos_x * @param integer $pos_x
* @param integer $pos_y * @param integer $pos_y
@@ -302,7 +302,7 @@ class Image
/** /**
* Fill image with given hexadecimal color at position x,y * Fill image with given hexadecimal color at position x,y
* *
* @param string $color * @param string $color
* @param integer $pos_x * @param integer $pos_x
* @param integer $pos_y * @param integer $pos_y
@@ -316,7 +316,7 @@ class Image
/** /**
* Set single pixel * Set single pixel
* *
* @param string $color * @param string $color
* @param integer $pos_x * @param integer $pos_x
* @param integer $pos_y * @param integer $pos_y
@@ -330,14 +330,14 @@ class Image
/** /**
* Draw rectangle in current image starting at point 1 and ending at point 2 * Draw rectangle in current image starting at point 1 and ending at point 2
* *
* @param string $color * @param string $color
* @param integer $x1 * @param integer $x1
* @param integer $y1 * @param integer $y1
* @param integer $x2 * @param integer $x2
* @param integer $y2 * @param integer $y2
* @param boolean $filled * @param boolean $filled
* @return Image * @return Image
*/ */
public function rectangle($color, $x1 = 0, $y1 = 0, $x2 = 10, $y2 = 10, $filled = true) public function rectangle($color, $x1 = 0, $y1 = 0, $x2 = 10, $y2 = 10, $filled = true)
{ {
@@ -348,12 +348,12 @@ class Image
/** /**
* Draw a line in current image starting at point 1 and ending at point 2 * Draw a line in current image starting at point 1 and ending at point 2
* *
* @param string $color * @param string $color
* @param integer $x1 * @param integer $x1
* @param integer $y1 * @param integer $y1
* @param integer $x2 * @param integer $x2
* @param integer $y2 * @param integer $y2
* @return Image * @return Image
*/ */
public function line($color, $x1 = 0, $y1 = 0, $x2 = 10, $y2 = 10) public function line($color, $x1 = 0, $y1 = 0, $x2 = 10, $y2 = 10)
@@ -364,12 +364,12 @@ class Image
/** /**
* Draw an ellipse centered at given coordinates. * Draw an ellipse centered at given coordinates.
* *
* @param string $color * @param string $color
* @param integer $x * @param integer $x
* @param integer $y * @param integer $y
* @param integer $width * @param integer $width
* @param integer $height * @param integer $height
* @return Image * @return Image
*/ */
public function ellipse($color, $x = 0, $y = 0, $width = 10, $height = 10, $filled = true) public function ellipse($color, $x = 0, $y = 0, $width = 10, $height = 10, $filled = true)
@@ -381,10 +381,10 @@ class Image
/** /**
* Draw a circle centered at given coordinates * Draw a circle centered at given coordinates
* *
* @param string $color * @param string $color
* @param integer $x * @param integer $x
* @param integer $y * @param integer $y
* @param integer $radius * @param integer $radius
* @param boolean $filled * @param boolean $filled
* @return Image * @return Image
@@ -396,25 +396,25 @@ class Image
/** /**
* Write text in current image * Write text in current image
* *
* @param string $text * @param string $text
* @param integer $pos_x * @param integer $pos_x
* @param integer $pos_y * @param integer $pos_y
* @param integer $angle * @param integer $angle
* @param integer $size * @param integer $size
* @param string $color * @param string $color
* @param string $fontfile * @param string $fontfile
* @return Image * @return Image
*/ */
public function text($text, $pos_x = 0, $pos_y = 0, $size = 16, $color = '000000', $angle = 0, $fontfile = null) public function text($text, $pos_x = 0, $pos_y = 0, $size = 16, $color = '000000', $angle = 0, $fontfile = null)
{ {
if (is_null($fontfile)) { if (is_null($fontfile)) {
imagestring($this->resource, $size, $pos_x, $pos_y, $text, $this->parseColor($color)); imagestring($this->resource, $size, $pos_x, $pos_y, $text, $this->parseColor($color));
} else { } else {
imagettftext($this->resource, $size, $angle, $pos_x, $pos_y, $this->parseColor($color), $fontfile, $text); imagettftext($this->resource, $size, $angle, $pos_x, $pos_y, $this->parseColor($color), $fontfile, $text);
} }
@@ -423,7 +423,7 @@ class Image
/** /**
* Changes the brightness of the current image * Changes the brightness of the current image
* *
* @param int $level [description] * @param int $level [description]
* @return Image * @return Image
*/ */
@@ -435,9 +435,9 @@ class Image
/** /**
* Changes the contrast of the current image * Changes the contrast of the current image
* *
* @param int $level * @param int $level
* @return Image * @return Image
*/ */
public function contrast($level) public function contrast($level)
{ {
@@ -447,10 +447,10 @@ class Image
/** /**
* Pixelate current image * Pixelate current image
* *
* @param integer $size * @param integer $size
* @param boolean $advanced * @param boolean $advanced
* @return Image * @return Image
*/ */
public function pixelate($size = 10, $advanced = true) public function pixelate($size = 10, $advanced = true)
{ {
@@ -460,7 +460,7 @@ class Image
/** /**
* Turn current image into a greyscale verision * Turn current image into a greyscale verision
* *
* @return Image * @return Image
*/ */
public function grayscale() public function grayscale()
@@ -471,7 +471,7 @@ class Image
/** /**
* Alias of greyscale * Alias of greyscale
* *
* @return Image * @return Image
*/ */
public function greyscale() public function greyscale()
@@ -482,18 +482,18 @@ class Image
/** /**
* Reset to original image resource * Reset to original image resource
* *
* @return void * @return void
*/ */
public function reset() public function reset()
{ {
$this->setProperties($this->dirname .'/'. $this->basename); $this->setProperties($this->dirname .'/'. $this->basename);
return $this; return $this;
} }
/** /**
* Returns image type stream * Returns image type stream
* *
* @param string $type gif|png|jpg|jpeg * @param string $type gif|png|jpg|jpeg
* @param integer quality * @param integer quality
* @return string * @return string
@@ -521,18 +521,18 @@ class Image
} }
$data = ob_get_contents(); $data = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $data; return $data;
} }
/** /**
* Picks and formats color at position * Picks and formats color at position
* *
* @param int $x * @param int $x
* @param int $y * @param int $y
* @param string $format * @param string $format
* @return mixed * @return mixed
*/ */
public function pickColor($x, $y, $format = null) public function pickColor($x, $y, $format = null)
{ {
@@ -555,18 +555,18 @@ class Image
$color = imagecolorsforindex($this->resource, $color); $color = imagecolorsforindex($this->resource, $color);
$color = sprintf('#%02x%02x%02x', $color['red'], $color['green'], $color['blue']); $color = sprintf('#%02x%02x%02x', $color['red'], $color['green'], $color['blue']);
break; break;
case 'array': case 'array':
$color = imagecolorsforindex($this->resource, $color); $color = imagecolorsforindex($this->resource, $color);
break; break;
} }
return $color; return $color;
} }
/** /**
* Allocate color from given string * Allocate color from given string
* *
* @param string $value * @param string $value
* @return int * @return int
*/ */
@@ -577,7 +577,7 @@ class Image
if (is_int($value)) { if (is_int($value)) {
// color is alread allocated // color is alread allocated
$allocatedColor = $value; $allocatedColor = $value;
} elseif(is_array($value)) { } elseif(is_array($value)) {
@@ -595,24 +595,24 @@ class Image
// parse color string in format rgb(140, 140, 140) // parse color string in format rgb(140, 140, 140)
} elseif (preg_match('/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i', $value, $matches)) { } elseif (preg_match('/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i', $value, $matches)) {
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0; $r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0; $g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
$b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0; $b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
// parse color string in format rgba(255, 0, 0, 0.5) // parse color string in format rgba(255, 0, 0, 0.5)
} elseif (preg_match('/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,3})\)$/i', $value, $matches)) { } elseif (preg_match('/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,3})\)$/i', $value, $matches)) {
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0; $r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0; $g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
$b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0; $b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
$alpha = $this->alpha2gd($matches[4]); $alpha = $this->alpha2gd($matches[4]);
} }
} }
if (isset($allocatedColor)) { if (isset($allocatedColor)) {
return $allocatedColor; return $allocatedColor;
} elseif (isset($r) && isset($g) && isset($b)) { } elseif (isset($r) && isset($g) && isset($b)) {
@@ -620,16 +620,16 @@ class Image
return imagecolorallocatealpha($this->resource, $r, $g, $b, $alpha); return imagecolorallocatealpha($this->resource, $r, $g, $b, $alpha);
} else { } else {
throw new Exception("Error parsing color [{$value}]"); throw new Exception("Error parsing color [{$value}]");
} }
} }
/** /**
* Save image in filesystem * Save image in filesystem
* *
* @param string $path * @param string $path
* @return Image * @return Image
*/ */
public function save($path = null, $quality = 90) public function save($path = null, $quality = 90)
{ {
@@ -664,7 +664,7 @@ class Image
/** /**
* Return filesystem object * Return filesystem object
* *
* @return Filesystem * @return Filesystem
*/ */
public function getFilesystem() public function getFilesystem()
@@ -674,11 +674,11 @@ class Image
/** /**
* Returns image stream * Returns image stream
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return $this->data(); return $this->data();
} }
} }

View File

@@ -1,46 +1,48 @@
<?php namespace Intervention\Image; <?php
use Illuminate\Support\ServiceProvider; namespace Intervention\Image;
class ImageServiceProvider extends ServiceProvider { use Illuminate\Support\ServiceProvider;
/** class ImageServiceProvider extends ServiceProvider
* Indicates if loading of the provider is deferred. {
*
* @var bool /**
*/ * Indicates if loading of the provider is deferred.
protected $defer = false; *
* @var bool
/** */
* Bootstrap the application events. protected $defer = false;
*
* @return void /**
*/ * Bootstrap the application events.
public function boot() *
{ * @return void
$this->package('intervention/image'); */
} public function boot()
{
/** $this->package('intervention/image');
* Register the service provider. }
*
* @return void /**
*/ * Register the service provider.
public function register() *
{ * @return void
$this->app['image'] = $this->app->share(function($app) { */
return new Image; public function register()
}); {
} $this->app['image'] = $this->app->share(function($app) {
return new Image;
/** });
* Get the services provided by the provider. }
*
* @return array /**
*/ * Get the services provided by the provider.
public function provides() *
{ * @return array
return array('image'); */
} public function provides()
{
} return array('image');
}
}

View File

@@ -98,7 +98,7 @@ class ImageTest extends PHPUnit_Framework_Testcase
$img = $this->getTestImage(); $img = $this->getTestImage();
$img->insert('public/test.jpg', 10, 10); $img->insert('public/test.jpg', 10, 10);
$this->assertInstanceOf('Intervention\Image\Image', $img); $this->assertInstanceOf('Intervention\Image\Image', $img);
} }
public function testPixelateImage() public function testPixelateImage()
@@ -192,8 +192,8 @@ class ImageTest extends PHPUnit_Framework_Testcase
$img = $this->getTestImage(); $img = $this->getTestImage();
$circle = new Image('public/circle.png'); $circle = new Image('public/circle.png');
for ($x=0; $x < $img->width; $x=$x+$circle->width) { for ($x=0; $x < $img->width; $x=$x+$circle->width) {
for ($y=0; $y < $img->height; $y=$y+$circle->height) { for ($y=0; $y < $img->height; $y=$y+$circle->height) {
// insert circle png at position x,y // insert circle png at position x,y
$img->insert($circle, $x, $y); $img->insert($circle, $x, $y);
} }
@@ -238,41 +238,41 @@ class ImageTest extends PHPUnit_Framework_Testcase
public function testPickColor() public function testPickColor()
{ {
$img = $this->getTestImage(); $img = $this->getTestImage();
// int color // int color
$color = $img->pickColor(100, 100); $color = $img->pickColor(100, 100);
$this->assertInternalType('int', $color); $this->assertInternalType('int', $color);
$this->assertEquals($color, 16776956); $this->assertEquals($color, 16776956);
// rgb color string // rgb color string
$color = $img->pickColor(799, 599, 'rgb'); $color = $img->pickColor(799, 599, 'rgb');
$this->assertInternalType('string', $color); $this->assertInternalType('string', $color);
$this->assertEquals($color, 'rgb(255, 166, 0)'); $this->assertEquals($color, 'rgb(255, 166, 0)');
// hex color string // hex color string
$color = $img->pickColor(799, 599, 'hex'); $color = $img->pickColor(799, 599, 'hex');
$this->assertInternalType('string', $color); $this->assertInternalType('string', $color);
$this->assertEquals($color, '#ffa600'); $this->assertEquals($color, '#ffa600');
// rgb color array // rgb color array
$color = $img->pickColor(799, 599, 'array'); $color = $img->pickColor(799, 599, 'array');
$this->assertInternalType('array', $color); $this->assertInternalType('array', $color);
$this->assertInternalType('int', $color['red']); $this->assertInternalType('int', $color['red']);
$this->assertEquals($color['red'], 255); $this->assertEquals($color['red'], 255);
$this->assertInternalType('int', $color['green']); $this->assertInternalType('int', $color['green']);
$this->assertEquals($color['green'], 166); $this->assertEquals($color['green'], 166);
$this->assertInternalType('int', $color['blue']); $this->assertInternalType('int', $color['blue']);
$this->assertEquals($color['blue'], 0); $this->assertEquals($color['blue'], 0);
// rgba color string // rgba color string
$color = $img->pickColor(799, 599, 'rgba'); $color = $img->pickColor(799, 599, 'rgba');
$this->assertInternalType('string', $color); $this->assertInternalType('string', $color);
$this->assertEquals($color, 'rgba(255, 166, 0, 1.00)'); $this->assertEquals($color, 'rgba(255, 166, 0, 1.00)');
$img = new Image(null, 100, 100); $img = new Image(null, 100, 100);
$color = imagecolorallocatealpha($img->resource, 0, 0, 255, 64); $color = imagecolorallocatealpha($img->resource, 0, 0, 255, 64);
$img->fill($color); $img->fill($color);
$color = $img->pickColor(50, 50, 'rgba'); $color = $img->pickColor(50, 50, 'rgba');
$this->assertInternalType('string', $color); $this->assertInternalType('string', $color);
$this->assertEquals($color, 'rgba(0, 0, 255, 0.50)'); $this->assertEquals($color, 'rgba(0, 0, 255, 0.50)');
} }
@@ -281,7 +281,7 @@ class ImageTest extends PHPUnit_Framework_Testcase
$img = $this->getTestImage(); $img = $this->getTestImage();
$color = $img->parseColor(array(155, 155, 155)); $color = $img->parseColor(array(155, 155, 155));
$this->assertInternalType('int', $color); $this->assertInternalType('int', $color);
$color = $img->parseColor('#cccccc'); $color = $img->parseColor('#cccccc');
$this->assertInternalType('int', $color); $this->assertInternalType('int', $color);
@@ -314,36 +314,36 @@ class ImageTest extends PHPUnit_Framework_Testcase
{ {
$img = new Image(null, 100, 100); $img = new Image(null, 100, 100);
$img->fill('rgb(255, 0, 0)'); $img->fill('rgb(255, 0, 0)');
$checkColor = $img->pickColor(50, 50,'array'); $checkColor = $img->pickColor(50, 50,'array');
$this->assertEquals($checkColor['red'], 255); $this->assertEquals($checkColor['red'], 255);
$this->assertEquals($checkColor['green'], 0); $this->assertEquals($checkColor['green'], 0);
$this->assertEquals($checkColor['blue'], 0); $this->assertEquals($checkColor['blue'], 0);
$this->assertEquals($checkColor['alpha'], 0); $this->assertEquals($checkColor['alpha'], 0);
$img->rectangle('rgba(0,0,0,0.5)', 0, 0, 100, 100); $img->rectangle('rgba(0,0,0,0.5)', 0, 0, 100, 100);
$checkColor = $img->pickColor(50, 50,'array'); $checkColor = $img->pickColor(50, 50,'array');
$this->assertEquals($checkColor['red'], 128); $this->assertEquals($checkColor['red'], 128);
$this->assertEquals($checkColor['green'], 0); $this->assertEquals($checkColor['green'], 0);
$this->assertEquals($checkColor['blue'], 0); $this->assertEquals($checkColor['blue'], 0);
$this->assertEquals($checkColor['alpha'], 0); $this->assertEquals($checkColor['alpha'], 0);
$img = new Image(null, 100, 100); $img = new Image(null, 100, 100);
$img->fill('rgba(0,0,0,0.5)'); $img->fill('rgba(0,0,0,0.5)');
$checkColor = $img->pickColor(50, 50,'array'); $checkColor = $img->pickColor(50, 50,'array');
$this->assertEquals($checkColor['red'], 0); $this->assertEquals($checkColor['red'], 0);
$this->assertEquals($checkColor['green'], 0); $this->assertEquals($checkColor['green'], 0);
$this->assertEquals($checkColor['blue'], 0); $this->assertEquals($checkColor['blue'], 0);
$this->assertEquals($checkColor['alpha'], 64); $this->assertEquals($checkColor['alpha'], 64);
$img = new Image(null, 100, 100); $img = new Image(null, 100, 100);
$color = imagecolorallocatealpha($img->resource, 0, 0, 255, 60); $color = imagecolorallocatealpha($img->resource, 0, 0, 255, 60);
$img->fill($color); $img->fill($color);
$checkColor = $img->pickColor(50, 50,'array'); $checkColor = $img->pickColor(50, 50,'array');
$this->assertEquals($checkColor['red'], 0); $this->assertEquals($checkColor['red'], 0);
$this->assertEquals($checkColor['green'], 0); $this->assertEquals($checkColor['green'], 0);
$this->assertEquals($checkColor['blue'], 255); $this->assertEquals($checkColor['blue'], 255);
$this->assertEquals($checkColor['alpha'], 60); $this->assertEquals($checkColor['alpha'], 60);
} }
public function testBrightnessImage() public function testBrightnessImage()
@@ -399,4 +399,4 @@ class ImageTest extends PHPUnit_Framework_Testcase
$this->assertEquals($color['blue'], 0); $this->assertEquals($color['blue'], 0);
$this->assertEquals($color['alpha'], 127); $this->assertEquals($color['alpha'], 127);
} }
} }