mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 00:29:55 +02:00
added checksumCommand
This commit is contained in:
23
src/Intervention/Image/Commands/ChecksumCommand.php
Normal file
23
src/Intervention/Image/Commands/ChecksumCommand.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Commands;
|
||||
|
||||
class ChecksumCommand extends AbstractCommand
|
||||
{
|
||||
public function execute($image)
|
||||
{
|
||||
$colors = array();
|
||||
|
||||
$size = $image->getSize();
|
||||
|
||||
for ($x=0; $x <= ($size->width-1); $x++) {
|
||||
for ($y=0; $y <= ($size->height-1); $y++) {
|
||||
$colors[] = $image->pickColor($x, $y, 'array');
|
||||
}
|
||||
}
|
||||
|
||||
$this->setOutput(md5(serialize($colors)));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
26
tests/ChecksumCommandTest.php
Normal file
26
tests/ChecksumCommandTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Intervention\Image\Commands\ChecksumCommand;
|
||||
|
||||
class ExifCommandTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$size = Mockery::mock('Intervention\Image\Size', array(3, 3));
|
||||
$color = array(0,0,0,1);
|
||||
$resource = imagecreatefrompng(__DIR__.'/images/tile.png');
|
||||
$image = Mockery::mock('Intervention\Image\Image');
|
||||
$image->shouldReceive('getSize')->once()->andReturn($size);
|
||||
$image->shouldReceive('pickColor')->times(9)->andReturn($color);
|
||||
$command = new ChecksumCommand(array());
|
||||
$result = $command->execute($image);
|
||||
$this->assertTrue($result);
|
||||
$this->assertTrue($command->hasOutput());
|
||||
$this->assertEquals('ec9cbdb71be04e26b4a89333f20c273b', $command->getOutput());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user