1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 20:51:20 +02:00

renamed classes

This commit is contained in:
Oliver Vogel
2014-06-05 17:25:48 +02:00
parent 8692a77fb6
commit 79bc7874e5
13 changed files with 124 additions and 47 deletions

View File

@@ -2,7 +2,7 @@
namespace Intervention\Image;
abstract class AbstractSource
abstract class AbstractDecoder
{
/**
* Initiates new image from path in filesystem
@@ -44,7 +44,7 @@ abstract class AbstractSource
private $data;
/**
* Creates new Source with data
* Creates new Decoder with data
*
* @param mixed $data
*/
@@ -180,7 +180,7 @@ abstract class AbstractSource
}
/**
* Source object transforms to string source data
* Decoder object transforms to string source data
*
* @return string
*/

View File

@@ -5,11 +5,11 @@ namespace Intervention\Image;
abstract class AbstractDriver
{
/**
* Source instance to init images from
* Decoder instance to init images from
*
* @var Intervention\Image\AbstractSource
* @var Intervention\Image\AbstractDecoder
*/
public $source;
public $decoder;
/**
* Image encoder instance
@@ -61,7 +61,7 @@ abstract class AbstractDriver
*/
public function init($data)
{
return $this->source->init($data);
return $this->decoder->init($data);
}
/**

View File

@@ -0,0 +1,68 @@
<?php
namespace Intervention\Image\Gd\Commands;
use Intervention\Image\Gd\Color;
class ColorsCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$number = $this->argument(0)->min(1)->value(5);
$accuracy = $this->argument(1)->between(1, 100)->value(100);
$format = $this->argument(2)->type('string')->value('hex');
$output = array();
$colors = array();
$size = $image->getSize();
$step_x = round($size->width / ($size->width / 100 * $accuracy));
$step_y = round($size->height / ($size->height / 100 * $accuracy));
// read colors from image
for ($x=0; $x < $size->width; $x=$x+$step_x) {
for ($y=0; $y < $size->height; $y=$y+$step_y) {
$color = imagecolorat($image->getCore(), $x, $y);
if (isset($colors[$color])) {
$colors[$color]++;
} else {
$colors[$color] = 1;
}
}
}
// sort colors by color-value
ksort($colors);
// consolidate colors
$compare_color = null;
foreach ($colors as $key => $value) {
$color = new Color($key);
if ( ! is_null($compare_color)) {
if ( ! $color->differs($compare_color, 80)) {
unset($colors[$key]);
} else {
$compare_color = $color;
}
} else {
$compare_color = $color;
}
}
// sort colors by appearance
arsort($colors);
// slice array
$colors = array_slice($colors, 0, $number, true);
// format colors
foreach ($colors as $color => $count) {
$color = new Color($color);
$output[] = $color->format($format);
}
$this->setOutput($output);
}
}

View File

@@ -2,7 +2,7 @@
namespace Intervention\Image\Gd\Commands;
use Intervention\Image\Gd\Source;
use Intervention\Image\Gd\Decoder;
use Intervention\Image\Gd\Color;
class FillCommand extends \Intervention\Image\Commands\AbstractCommand
@@ -26,7 +26,7 @@ class FillCommand extends \Intervention\Image\Commands\AbstractCommand
try {
// set image tile filling
$source = new Source;
$source = new Decoder;
$tile = $source->init($filling);
imagesettile($image->getCore(), $tile->getCore());
$filling = IMG_COLOR_TILED;

View File

@@ -5,7 +5,7 @@ namespace Intervention\Image\Gd;
use \Intervention\Image\Image;
use \Intervention\Image\Size;
class Source extends \Intervention\Image\AbstractSource
class Decoder extends \Intervention\Image\AbstractDecoder
{
/**
* Initiates new image from path in filesystem

View File

@@ -9,10 +9,10 @@ class Driver extends \Intervention\Image\AbstractDriver
/**
* Creates new instance of driver
*
* @param Intervention\Image\Gd\Source $source
* @param Intervention\Image\Gd\Decoder $decoder
* @param Intervention\Image\Gd\Encoder $encoder
*/
public function __construct(Source $source = null, Encoder $encoder = null)
public function __construct(Decoder $decoder = null, Encoder $encoder = null)
{
if ( ! $this->coreAvailable()) {
throw new \Intervention\Image\Exception\NotSupportedException(
@@ -20,7 +20,7 @@ class Driver extends \Intervention\Image\AbstractDriver
);
}
$this->source = $source ? $source : new Source;
$this->decoder = $decoder ? $decoder : new Decoder;
$this->encoder = $encoder ? $encoder : new Encoder;
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Intervention\Image\Imagick\Commands;
class ColorsCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
# code...
}
}

View File

@@ -3,7 +3,7 @@
namespace Intervention\Image\Imagick\Commands;
use \Intervention\Image\Image;
use \Intervention\Image\Imagick\Source;
use \Intervention\Image\Imagick\Decoder;
use \Intervention\Image\Imagick\Color;
class FillCommand extends \Intervention\Image\Commands\AbstractCommand
@@ -24,7 +24,7 @@ class FillCommand extends \Intervention\Image\Commands\AbstractCommand
try {
// set image filling
$source = new Source;
$source = new Decoder;
$filling = $source->init($filling);
} catch (\Intervention\Image\Exception\NotReadableException $e) {

View File

@@ -2,8 +2,6 @@
namespace Intervention\Image\Imagick\Commands;
use \Intervention\Image\Imagick\Source;
class InsertCommand extends \Intervention\Image\Commands\AbstractCommand
{
/**

View File

@@ -5,7 +5,7 @@ namespace Intervention\Image\Imagick;
use \Intervention\Image\Image;
use \Intervention\Image\Size;
class Source extends \Intervention\Image\AbstractSource
class Decoder extends \Intervention\Image\AbstractDecoder
{
/**
* Initiates new image from path in filesystem

View File

@@ -9,10 +9,10 @@ class Driver extends \Intervention\Image\AbstractDriver
/**
* Creates new instance of driver
*
* @param Intervention\Image\Imagick\Source $source
* @param Intervention\Image\Imagick\Decoder $decoder
* @param Intervention\Image\Imagick\Encoder $encoder
*/
public function __construct(Source $source = null, Encoder $encoder = null)
public function __construct(Decoder $decoder = null, Encoder $encoder = null)
{
if ( ! $this->coreAvailable()) {
throw new \Intervention\Image\Exception\NotSupportedException(
@@ -20,7 +20,7 @@ class Driver extends \Intervention\Image\AbstractDriver
);
}
$this->source = $source ? $source : new Source;
$this->decoder = $decoder ? $decoder : new Decoder;
$this->encoder = $encoder ? $encoder : new Encoder;
}

View File

@@ -1,8 +1,8 @@
<?php
use \Intervention\Image\AbstractSource;
use \Intervention\Image\AbstractDecoder;
class AbstractSourceTest extends PHPUnit_Framework_TestCase
class AbstractDecoderTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
@@ -11,76 +11,76 @@ class AbstractSourceTest extends PHPUnit_Framework_TestCase
public function testIsImagick()
{
$source = $this->getTestSource(new \Imagick);
$source = $this->getTestDecoder(new \Imagick);
$this->assertTrue($source->isImagick());
$source = $this->getTestSource(new StdClass);
$source = $this->getTestDecoder(new StdClass);
$this->assertFalse($source->isImagick());
$source = $this->getTestSource(null);
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isImagick());
}
public function testIsGdResource()
{
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$source = $this->getTestSource($resource);
$source = $this->getTestDecoder($resource);
$this->assertTrue($source->isGdResource());
$source = $this->getTestSource(tmpfile());
$source = $this->getTestDecoder(tmpfile());
$this->assertFalse($source->isGdResource());
$source = $this->getTestSource(null);
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isGdResource());
}
public function testIsFilepath()
{
$source = $this->getTestSource(__DIR__.'/AbstractSourceTest.php');
$source = $this->getTestDecoder(__DIR__.'/AbstractDecoderTest.php');
$this->assertTrue($source->isFilepath());
$source = $this->getTestSource(null);
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isFilepath());
$source = $this->getTestSource(array());
$source = $this->getTestDecoder(array());
$this->assertFalse($source->isFilepath());
$source = $this->getTestSource(new StdClass);
$source = $this->getTestDecoder(new StdClass);
$this->assertFalse($source->isFilepath());
}
public function testIsUrl()
{
$source = $this->getTestSource('http://foo.bar');
$source = $this->getTestDecoder('http://foo.bar');
$this->assertTrue($source->isUrl());
$source = $this->getTestSource(null);
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isUrl());
}
public function testIsBinary()
{
$source = $this->getTestSource(file_get_contents(__DIR__.'/images/test.jpg'));
$source = $this->getTestDecoder(file_get_contents(__DIR__.'/images/test.jpg'));
$this->assertTrue($source->isBinary());
$source = $this->getTestSource(null);
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isBinary());
$source = $this->getTestSource(1);
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isBinary());
$source = $this->getTestSource(0);
$source = $this->getTestDecoder(0);
$this->assertFalse($source->isBinary());
$source = $this->getTestSource(array(1,2,3));
$source = $this->getTestDecoder(array(1,2,3));
$this->assertFalse($source->isBinary());
$source = $this->getTestSource(new StdClass);
$source = $this->getTestDecoder(new StdClass);
$this->assertFalse($source->isBinary());
}
public function getTestSource($data)
public function getTestDecoder($data)
{
return $this->getMockForAbstractClass('\Intervention\Image\AbstractSource', array($data));
return $this->getMockForAbstractClass('\Intervention\Image\AbstractDecoder', array($data));
}
}

View File

@@ -13,7 +13,7 @@ class DriverTest extends PHPUnit_Framework_TestCase
public function testNewImageGd()
{
$driver = new GdDriver(
Mockery::mock('\Intervention\Image\Gd\Source'),
Mockery::mock('\Intervention\Image\Gd\Decoder'),
Mockery::mock('\Intervention\Image\Gd\Encoder')
);
@@ -26,7 +26,7 @@ class DriverTest extends PHPUnit_Framework_TestCase
public function testNewImageImagick()
{
$driver = new ImagickDriver(
Mockery::mock('\Intervention\Image\Imagick\Source'),
Mockery::mock('\Intervention\Image\Imagick\Decoder'),
Mockery::mock('\Intervention\Image\Imagick\Encoder')
);
@@ -39,7 +39,7 @@ class DriverTest extends PHPUnit_Framework_TestCase
public function testParseColorGd()
{
$driver = new GdDriver(
Mockery::mock('\Intervention\Image\Gd\Source'),
Mockery::mock('\Intervention\Image\Gd\Decoder'),
Mockery::mock('\Intervention\Image\Gd\Encoder')
);
@@ -50,7 +50,7 @@ class DriverTest extends PHPUnit_Framework_TestCase
public function testParseColorImagick()
{
$driver = new ImagickDriver(
Mockery::mock('\Intervention\Image\Imagick\Source'),
Mockery::mock('\Intervention\Image\Imagick\Decoder'),
Mockery::mock('\Intervention\Image\Imagick\Encoder')
);