Update v1.0.6
|
After Width: | Height: | Size: 330 B |
|
After Width: | Height: | Size: 570 B |
|
After Width: | Height: | Size: 727 B |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 704 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 240 B |
|
After Width: | Height: | Size: 321 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 298 B |
|
After Width: | Height: | Size: 199 B |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1 @@
|
||||
NOT AN ACTUAL IMAGE
|
||||
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1 @@
|
||||
Fake image with custom extension
|
||||
@@ -0,0 +1 @@
|
||||
Fake image with custom extension
|
||||
|
After Width: | Height: | Size: 3.4 KiB |
@@ -0,0 +1 @@
|
||||
phpunit --verbose --bootstrap test-init.php %1 %2 %3 %4 %5 %6 tests
|
||||
@@ -0,0 +1 @@
|
||||
phpunit $* --verbose --bootstrap `dirname $0`/test-init.php `dirname $0`/tests
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
require dirname(__FILE__) . '/../lib/WideImage.php';
|
||||
|
||||
define('TEST_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
|
||||
define('IMG_PATH', TEST_PATH . 'images' . DIRECTORY_SEPARATOR);
|
||||
|
||||
abstract class WideImage_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function load($file)
|
||||
{
|
||||
return WideImage::load(IMG_PATH . $file);
|
||||
}
|
||||
|
||||
function assertValidImage($image)
|
||||
{
|
||||
$this->assertInstanceOf("WideImage_Image", $image);
|
||||
$this->assertTrue($image->isValid());
|
||||
}
|
||||
|
||||
function assertDimensions($image, $width, $height)
|
||||
{
|
||||
$this->assertEquals($width, $image->getWidth());
|
||||
$this->assertEquals($height, $image->getHeight());
|
||||
}
|
||||
|
||||
function assertTransparentColorMatch($img1, $img2)
|
||||
{
|
||||
$tc1 = $img1->getTransparentColorRGB();
|
||||
$tc2 = $img2->getTransparentColorRGB();
|
||||
$this->assertEquals($tc1, $tc2);
|
||||
}
|
||||
|
||||
function assertTransparentColorAt($img, $x, $y)
|
||||
{
|
||||
$this->assertEquals($img->getTransparentColor(), $img->getColorAt($x, $y));
|
||||
}
|
||||
|
||||
function assertRGBWithinMargin($rec, $r, $g, $b, $a, $margin)
|
||||
{
|
||||
if (is_array($r))
|
||||
{
|
||||
$a = $r['alpha'];
|
||||
$b = $r['blue'];
|
||||
$g = $r['green'];
|
||||
$r = $r['red'];
|
||||
}
|
||||
|
||||
$result =
|
||||
abs($rec['red'] - $r) <= $margin &&
|
||||
abs($rec['green'] - $g) <= $margin &&
|
||||
abs($rec['blue'] - $b) <= $margin;
|
||||
|
||||
$result = $result && ($a === null || abs($rec['alpha'] - $a) <= $margin);
|
||||
|
||||
$this->assertTrue($result,
|
||||
"RGBA [{$rec['red']}, {$rec['green']}, {$rec['blue']}, {$rec['alpha']}] " .
|
||||
"doesn't match RGBA [$r, $g, $b, $a] within margin [$margin].");
|
||||
}
|
||||
|
||||
function assertRGBAt($img, $x, $y, $rgba)
|
||||
{
|
||||
if (is_array($rgba))
|
||||
$cmp = $img->getRGBAt($x, $y);
|
||||
else
|
||||
$cmp = $img->getColorAt($x, $y);
|
||||
$this->assertSame($cmp, $rgba);
|
||||
}
|
||||
|
||||
function assertRGBNear($rec, $r, $g = null, $b = null, $a = null)
|
||||
{
|
||||
$this->assertRGBWithinMargin($rec, $r, $g, $b, $a, 2);
|
||||
}
|
||||
|
||||
function assertRGBEqual($rec, $r, $g = null, $b = null, $a = null)
|
||||
{
|
||||
$this->assertRGBWithinMargin($rec, $r, $g, $b, $a, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Canvas_Test extends WideImage_TestCase
|
||||
{
|
||||
function testCreate()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(10, 10);
|
||||
|
||||
$canvas1 = $img->getCanvas();
|
||||
$this->assertInstanceOf('WideImage_Canvas', $canvas1);
|
||||
|
||||
$canvas2 = $img->getCanvas();
|
||||
$this->assertSame($canvas1, $canvas2);
|
||||
}
|
||||
|
||||
function testMagicCallDrawRectangle()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(10, 10);
|
||||
$canvas = $img->getCanvas();
|
||||
$canvas->filledRectangle(1, 1, 5, 5, $img->allocateColorAlpha(255, 0, 0, 64));
|
||||
$this->assertRGBAt($img, 3, 3, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 64));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Coordinate_Test extends WideImage_TestCase
|
||||
{
|
||||
function testEvaluate()
|
||||
{
|
||||
$this->assertSame(400, WideImage_Coordinate::evaluate('+200%', 200));
|
||||
$this->assertSame(-1, WideImage_Coordinate::evaluate('-1', 200));
|
||||
$this->assertSame(10, WideImage_Coordinate::evaluate('+10', 200));
|
||||
$this->assertSame(40, WideImage_Coordinate::evaluate('+20%', 200));
|
||||
$this->assertSame(-11, WideImage_Coordinate::evaluate('-11.23', 200));
|
||||
$this->assertSame(-30, WideImage_Coordinate::evaluate('-15%', 200));
|
||||
}
|
||||
|
||||
function testFix()
|
||||
{
|
||||
$this->assertSame(10, WideImage_Coordinate::fix('10%', 100));
|
||||
$this->assertSame(10, WideImage_Coordinate::fix('10', 100));
|
||||
|
||||
$this->assertSame(-10, WideImage_Coordinate::fix('-10%', 100));
|
||||
$this->assertSame(-1, WideImage_Coordinate::fix('-1', 100));
|
||||
$this->assertSame(-50, WideImage_Coordinate::fix('-50%', 100));
|
||||
$this->assertSame(-100, WideImage_Coordinate::fix('-100%', 100));
|
||||
$this->assertSame(-1, WideImage_Coordinate::fix('-5%', 20));
|
||||
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('150.12%', 200));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('150', 200));
|
||||
|
||||
$this->assertSame(100, WideImage_Coordinate::fix('100%-50%', 200));
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('100%', 200));
|
||||
|
||||
$this->assertSame(130, WideImage_Coordinate::fix('50% -20', 300));
|
||||
$this->assertSame(12, WideImage_Coordinate::fix(' 12 - 0', 300));
|
||||
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%', 30));
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%-0', 30));
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%+0', 30));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix(' - 50% + 50%', 30));
|
||||
$this->assertSame(30, WideImage_Coordinate::fix(' 50% + 49.6666%', 30));
|
||||
}
|
||||
|
||||
function testAlign()
|
||||
{
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('left', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('center', 300, 120));
|
||||
$this->assertSame(180, WideImage_Coordinate::fix('right', 300, 120));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('top', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('middle', 300, 120));
|
||||
$this->assertSame(180, WideImage_Coordinate::fix('bottom', 300, 120));
|
||||
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('bottom+20', 300, 120));
|
||||
$this->assertSame(178, WideImage_Coordinate::fix('-2 + right', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('right - center', 300, 120));
|
||||
}
|
||||
|
||||
function testAlignWithoutSecondaryCoordinate()
|
||||
{
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('left', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('center', 300));
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('right', 300));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('top', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('middle', 300));
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('bottom', 300));
|
||||
|
||||
$this->assertSame(320, WideImage_Coordinate::fix('bottom+20', 300));
|
||||
$this->assertSame(280, WideImage_Coordinate::fix('-20 + right', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('right - center', 300));
|
||||
}
|
||||
|
||||
function testMultipleOperands()
|
||||
{
|
||||
$this->assertSame(6, WideImage_Coordinate::fix('100%-100+1 + 5', 100));
|
||||
$this->assertSame(1, WideImage_Coordinate::fix('right +1- 100 - 50%', 200));
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('-right+right +100%', 200));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('100--++++-10', 200));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidCoordinateException
|
||||
*/
|
||||
function testInvalidSyntaxEndsWithOperator()
|
||||
{
|
||||
WideImage_Coordinate::fix('5+2+', 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_CustomOp
|
||||
{
|
||||
static public $args = null;
|
||||
|
||||
function execute()
|
||||
{
|
||||
self::$args = func_get_args();
|
||||
return self::$args[0]->copy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class ImageForOutput extends WideImage_TrueColorImage
|
||||
{
|
||||
public $headers = array();
|
||||
|
||||
function writeHeader($name, $data)
|
||||
{
|
||||
$this->headers[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class TestableImage extends WideImage_TrueColorImage
|
||||
{
|
||||
public $headers = array();
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function writeHeader($name, $data)
|
||||
{
|
||||
$this->headers[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Image_Test extends WideImage_TestCase
|
||||
{
|
||||
function testFactories()
|
||||
{
|
||||
$this->assertTrue(WideImage::createTrueColorImage(100, 100) instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue(WideImage::createPaletteImage(100, 100) instanceof WideImage_PaletteImage);
|
||||
}
|
||||
|
||||
function testDestructorUponUnset()
|
||||
{
|
||||
$img = $this->getMock('WideImage_TrueColorImage', array(), array(imagecreatetruecolor(10, 10)));
|
||||
$img->expectOnce('destroy');
|
||||
unset($img);
|
||||
$img = null;
|
||||
|
||||
for ($i = 0; $i++; $i < 1000);
|
||||
}
|
||||
|
||||
function testDestructorUponNull()
|
||||
{
|
||||
$img = $this->getMock('WideImage_TrueColorImage', array(), array(imagecreatetruecolor(10, 10)));
|
||||
$img->expectOnce('destroy');
|
||||
$img = null;
|
||||
|
||||
for ($i = 0; $i++; $i < 1000);
|
||||
}
|
||||
|
||||
function testAutoDestruct()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$handle = $img->getHandle();
|
||||
|
||||
unset($img);
|
||||
|
||||
$this->assertFalse(WideImage::isValidImageHandle($handle));
|
||||
}
|
||||
|
||||
function testAutoDestructWithRelease()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$handle = $img->getHandle();
|
||||
|
||||
$img->releaseHandle();
|
||||
unset($img);
|
||||
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testCustomOpMagic()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->customOp(123, 'abc');
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
|
||||
}
|
||||
|
||||
function testCustomOpCaseInsensitive()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->CUSTomOP(123, 'abc');
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
|
||||
}
|
||||
|
||||
function testInternalOpCaseInsensitive()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->AUTOcrop();
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
}
|
||||
|
||||
function testOutput()
|
||||
{
|
||||
$tmp = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$img = new ImageForOutput($tmp->getHandle());
|
||||
|
||||
ob_start();
|
||||
$img->output('png');
|
||||
$data = ob_get_clean();
|
||||
|
||||
$this->assertEquals(array('Content-length' => strlen($data), 'Content-type' => 'image/png'), $img->headers);
|
||||
}
|
||||
|
||||
function testCanvasInstance()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$canvas1 = $img->getCanvas();
|
||||
$this->assertTrue($canvas1 instanceof WideImage_Canvas);
|
||||
$canvas2 = $img->getCanvas();
|
||||
$this->assertTrue($canvas1 === $canvas2);
|
||||
}
|
||||
|
||||
function testSerializeTrueColorImage()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$img2 = unserialize(serialize($img));
|
||||
$this->assertEquals(get_class($img2), get_class($img));
|
||||
$this->assertTrue($img2->isTrueColor());
|
||||
$this->assertTrue($img2->isValid());
|
||||
$this->assertFalse($img2->isTransparent());
|
||||
$this->assertEquals($img->getWidth(), $img2->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $img2->getHeight());
|
||||
}
|
||||
|
||||
function testSerializePaletteImage()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$img2 = unserialize(serialize($img));
|
||||
$this->assertEquals(get_class($img2), get_class($img));
|
||||
$this->assertFalse($img2->isTrueColor());
|
||||
$this->assertTrue($img2->isValid());
|
||||
$this->assertTrue($img2->isTransparent());
|
||||
$this->assertEquals($img->getWidth(), $img2->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $img2->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/BMP.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_BMP_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_BMP
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'bmp');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . 'fgnl.bmp');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(174, imagesx($handle));
|
||||
$this->assertEquals(287, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = WideImage_vendor_de77_BMP::imagecreatefrombmp(IMG_PATH . 'fgnl.bmp');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = $this->mapper->loadFromString($string);
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.bmp');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.bmp') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = $this->mapper->load(IMG_PATH . 'temp/test.bmp');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/GD2.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_GD2_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd2');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.gd2'))
|
||||
unlink(IMG_PATH . 'temp/test.gd2');
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.gd2');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.gd2') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromgd2(IMG_PATH . 'temp/test.gd2');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/GD.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_GD_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_GD
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.gd'))
|
||||
unlink(IMG_PATH . 'temp/test.gd');
|
||||
}
|
||||
|
||||
function testSaveAndLoad()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.gd');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.gd') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = $this->mapper->load(IMG_PATH . 'temp/test.gd');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/GIF.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*
|
||||
* @group Mapper
|
||||
* @group GIF
|
||||
*/
|
||||
class WideImage_Mapper_GIF_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gif');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.gif'))
|
||||
unlink(IMG_PATH . 'temp/test.gif');
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.gif');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.gif') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromgif(IMG_PATH . 'temp/test.gif');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/JPEG.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_JPEG_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'jpg');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.jpg'))
|
||||
unlink(IMG_PATH . 'temp/test.jpg');
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . 'fgnl.jpg');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(174, imagesx($handle));
|
||||
$this->assertEquals(287, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'fgnl.jpg');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'fgnl.jpg');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.jpg');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.jpg') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'temp/test.jpg');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testQuality()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'fgnl.jpg');
|
||||
|
||||
ob_start();
|
||||
$this->mapper->save($handle, null, 100);
|
||||
$hq = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
$this->mapper->save($handle, null, 10);
|
||||
$lq = ob_get_clean();
|
||||
|
||||
$this->assertTrue(strlen($hq) > 0);
|
||||
$this->assertTrue(strlen($lq) > 0);
|
||||
$this->assertTrue(strlen($hq) > strlen($lq));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/PNG.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_PNG_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'png');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.png'))
|
||||
unlink(IMG_PATH . 'temp/test.png');
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . '100x100-color-hole.png');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH . '100x100-color-hole.png');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH . '100x100-color-hole.png');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.png');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.png') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefrompng(IMG_PATH . 'temp/test.png');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveCompression()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . '100x100-rainbow.png');
|
||||
$file1 = IMG_PATH . 'temp/test-comp-0.png';
|
||||
$file2 = IMG_PATH . 'temp/test-comp-9.png';
|
||||
$this->mapper->save($handle, $file1, 0);
|
||||
$this->mapper->save($handle, $file2, 9);
|
||||
$this->assertTrue(filesize($file1) > filesize($file2));
|
||||
|
||||
unlink($file1);
|
||||
unlink($file2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/TGA.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group mapper
|
||||
*/
|
||||
class WideImage_Mapper_TGA_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_TGA
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'tga');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . 'splat.tga');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
function testSaveToStringNotSupported()
|
||||
{
|
||||
$handle = WideImage_vendor_de77_BMP::imagecreatefrombmp(IMG_PATH . 'splat.tga');
|
||||
$this->mapper->save($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
function testSaveToFileNotSupported()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.bmp');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_MapperFactory_Test extends WideImage_TestCase
|
||||
{
|
||||
function testMapperPNGByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.png');
|
||||
$this->assertInstanceOf("WideImage_Mapper_PNG", $mapper);
|
||||
}
|
||||
|
||||
function testMapperGIFByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.gif');
|
||||
$this->assertInstanceOf("WideImage_Mapper_GIF", $mapper);
|
||||
}
|
||||
|
||||
function testMapperJPGByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.jpg');
|
||||
$this->assertInstanceOf("WideImage_Mapper_JPEG", $mapper);
|
||||
}
|
||||
|
||||
function testMapperBMPByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.bmp');
|
||||
$this->assertInstanceOf("WideImage_Mapper_BMP", $mapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_ApplyConvolution_Test extends WideImage_TestCase
|
||||
{
|
||||
function testApplyConvolution()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$result = $img->applyConvolution(array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1)), 1, 220);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_ApplyFilter_Test extends WideImage_TestCase
|
||||
{
|
||||
function testApplyFilter()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$result = $img->applyFilter(IMG_FILTER_EDGEDETECT);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_ApplyMask_Test extends WideImage_TestCase
|
||||
{
|
||||
function testApplyMask()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$mask = WideImage::load(IMG_PATH . '75x25-gray.png');
|
||||
|
||||
$result = $img->applyMask($mask);
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
|
||||
$this->assertRGBNear($result->getRGBAt(10, 10), 255, 255, 255);
|
||||
$this->assertRGBNear($result->getRGBAt(30, 10), 255, 255, 0, 64);
|
||||
$this->assertRGBNear($result->getRGBAt(60, 10), 0, 0, 255, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_AsGrayscale_Test extends WideImage_TestCase
|
||||
{
|
||||
function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagefilter'));
|
||||
}
|
||||
|
||||
function testTransparentGIF()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$gray = $img->asGrayscale();
|
||||
$this->assertTrue($gray instanceof WideImage_PaletteImage);
|
||||
|
||||
$this->assertEquals(100, $gray->getWidth());
|
||||
$this->assertEquals(100, $gray->getHeight());
|
||||
|
||||
$this->assertRGBNear($gray->getRGBAt(10, 10), 227, 227, 227);
|
||||
$this->assertRGBNear($gray->getRGBAt(90, 10), 28, 28, 28);
|
||||
$this->assertRGBNear($gray->getRGBAt(90, 90), 150, 150, 150);
|
||||
$this->assertRGBNear($gray->getRGBAt(10, 90), 76, 76, 76);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($gray->isTransparent());
|
||||
$this->assertEquals($gray->getColorAt(50, 50), $gray->getTransparentColor());
|
||||
}
|
||||
|
||||
function testTransparentLogoGIF()
|
||||
{
|
||||
$img = $this->load('logo.gif');
|
||||
$this->assertTransparentColorAt($img, 1, 1);
|
||||
|
||||
$res = $img->asGrayscale();
|
||||
$this->assertDimensions($res, 150, 23);
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", $res);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 1, 1);
|
||||
}
|
||||
|
||||
function testPNGAlpha()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
|
||||
$gray = $img->asGrayscale();
|
||||
$this->assertTrue($gray instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(100, $gray->getWidth());
|
||||
$this->assertEquals(100, $gray->getHeight());
|
||||
|
||||
$this->assertRGBNear($gray->getRGBAt(25, 25), 29, 29, 29, 32);
|
||||
$this->assertRGBNear($gray->getRGBAt(75, 25), 29, 29, 29, 64);
|
||||
$this->assertRGBNear($gray->getRGBAt(75, 75), 29, 29, 29, 96);
|
||||
$this->assertRGBNear($gray->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
|
||||
$this->assertFalse($gray->isTransparent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_AsNegativeTest extends WideImage_TestCase
|
||||
{
|
||||
function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagefilter'));
|
||||
}
|
||||
|
||||
function testTransparentGIF()
|
||||
{
|
||||
$img = $this->load('100x100-color-hole.gif');
|
||||
|
||||
$res = $img->asNegative();
|
||||
|
||||
$this->assertDimensions($res, 100, 100);
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", $res);
|
||||
|
||||
$this->assertRGBNear($res->getRGBAt(10, 10), 0, 0, 255);
|
||||
$this->assertRGBNear($res->getRGBAt(90, 10), 255, 255, 0);
|
||||
$this->assertRGBNear($res->getRGBAt(90, 90), 255, 0, 255);
|
||||
$this->assertRGBNear($res->getRGBAt(10, 90), 0, 255, 255);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 50, 50);
|
||||
}
|
||||
|
||||
function testTransparentLogoGIF()
|
||||
{
|
||||
$img = $this->load('logo.gif');
|
||||
$this->assertTransparentColorAt($img, 1, 1);
|
||||
|
||||
$res = $img->asNegative();
|
||||
$this->assertDimensions($res, 150, 23);
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", $res);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 1, 1);
|
||||
}
|
||||
|
||||
function testPNGAlpha()
|
||||
{
|
||||
$img = $this->load('100x100-blue-alpha.png');
|
||||
|
||||
$res = $img->asNegative();
|
||||
|
||||
$this->assertDimensions($res, 100, 100);
|
||||
$this->assertInstanceOf("WideImage_TrueColorImage", $res);
|
||||
|
||||
$this->assertRGBNear($res->getRGBAt(25, 25), 255, 255, 0, 32);
|
||||
$this->assertRGBNear($res->getRGBAt(75, 25), 255, 255, 0, 64);
|
||||
$this->assertRGBNear($res->getRGBAt(75, 75), 255, 255, 0, 96);
|
||||
$this->assertRGBNear($res->getRGBAt(25, 75), 255, 255, 255, 127);
|
||||
|
||||
$this->assertFalse($res->isTransparent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_Autocrop_Test extends WideImage_TestCase
|
||||
{
|
||||
function testAutocrop()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-red-spot.png');
|
||||
|
||||
$cropped = $img->autocrop();
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(71, $cropped->getWidth());
|
||||
$this->assertEquals(70, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
|
||||
}
|
||||
|
||||
function testAutocropHalfImageBug()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-red-spot-half-cut.png');
|
||||
|
||||
$cropped = $img->autocrop();
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(22, $cropped->getWidth());
|
||||
$this->assertEquals(23, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_CorrectGamma_Test extends WideImage_TestCase
|
||||
{
|
||||
function test()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$result = $img->correctGamma(1, 2);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_Crop_Test extends WideImage_TestCase
|
||||
{
|
||||
function testCropTransparentGif()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$cropped = $img->crop('10%', 15, 50, '40%');
|
||||
|
||||
$this->assertTrue($cropped instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($cropped->isTransparent());
|
||||
$this->assertEquals(50, $cropped->getWidth());
|
||||
$this->assertEquals(40, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(39, 9), 255, 255, 0);
|
||||
$this->assertRGBNear($cropped->getRGBAt(40, 9), 0, 0, 255);
|
||||
$this->assertRGBNear($cropped->getRGBAt(14, 35), 255, 0, 0);
|
||||
$this->assertRGBNear($cropped->getRGBAt(16, 11), $cropped->getTransparentColorRGB());
|
||||
}
|
||||
|
||||
function testCropPNGAlpha()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
|
||||
$cropped = $img->crop(10, 10, 50, 50);
|
||||
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertFalse($cropped->isTransparent());
|
||||
$this->assertEquals(50, $cropped->getWidth());
|
||||
$this->assertEquals(50, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(39, 39), 0, 0, 255, 32);
|
||||
$this->assertRGBNear($cropped->getRGBAt(40, 40), 0, 0, 255, 96);
|
||||
}
|
||||
|
||||
function testCropHasCorrectSize()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
|
||||
$cropped = $img->crop(10, 10, 10, 10);
|
||||
$this->assertEquals(10, $cropped->getWidth());
|
||||
$this->assertEquals(10, $cropped->getHeight());
|
||||
|
||||
$cropped = $img->crop(10, 20, 100, 200);
|
||||
$this->assertEquals(90, $cropped->getWidth());
|
||||
$this->assertEquals(80, $cropped->getHeight());
|
||||
}
|
||||
|
||||
function testCropIsNormalized()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
|
||||
$cropped = $img->crop(-10, -20, 100, 100);
|
||||
$this->assertEquals(90, $cropped->getWidth());
|
||||
$this->assertEquals(80, $cropped->getHeight());
|
||||
|
||||
$cropped = $img->crop(10, 20, 140, 170);
|
||||
$this->assertEquals(90, $cropped->getWidth());
|
||||
$this->assertEquals(80, $cropped->getHeight());
|
||||
|
||||
$cropped = $img->crop(-10, -20, 140, 170);
|
||||
$this->assertEquals(100, $cropped->getWidth());
|
||||
$this->assertEquals(100, $cropped->getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
function testCropCutsAreaOutsideBoundaries()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$cropped = $img->crop(120, 100, 1, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
function testCropCutsAreaNegativePosition()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$cropped = $img->crop(-150, -200, 50, 50);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class FlipTest extends WideImage_TestCase
|
||||
{
|
||||
function testFlip()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$this->assertRGBEqual($img->getRGBAt(5, 5), 255, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(95, 5), 0, 0, 255);
|
||||
$this->assertRGBEqual($img->getRGBAt(95, 95), 0, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(5, 95), 255, 0, 0);
|
||||
|
||||
$new = $img->flip();
|
||||
|
||||
$this->assertTrue($new instanceof WideImage_PaletteImage);
|
||||
|
||||
$this->assertEquals(100, $new->getWidth());
|
||||
$this->assertEquals(100, $new->getHeight());
|
||||
|
||||
$this->assertRGBEqual($new->getRGBAt(5, 95), 255, 255, 0);
|
||||
$this->assertRGBEqual($new->getRGBAt(95, 95), 0, 0, 255);
|
||||
$this->assertRGBEqual($new->getRGBAt(95, 5), 0, 255, 0);
|
||||
$this->assertRGBEqual($new->getRGBAt(5, 5), 255, 0, 0);
|
||||
|
||||
$this->assertTrue($new->isTransparent());
|
||||
$this->assertRGBEqual($new->getRGBAt(50, 50), $img->getTransparentColorRGB());
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_GetChannels_Test extends WideImage_TestCase
|
||||
{
|
||||
function testCopyChannel8bit()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$copy = $img->getChannels('red', 'alpha');
|
||||
$this->assertTrue($copy instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertFalse($copy->isTrueColor());
|
||||
$this->assertTrue($copy->isTransparent());
|
||||
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0);
|
||||
$this->assertEquals($copy->getTransparentColor(), $copy->getColorAt(50, 50));
|
||||
|
||||
$copy = $img->getChannels('red');
|
||||
$this->assertTrue($copy instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertFalse($copy->isTrueColor());
|
||||
$this->assertTrue($copy->isTransparent());
|
||||
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0);
|
||||
$this->assertEquals($copy->getTransparentColor(), $copy->getColorAt(50, 50));
|
||||
|
||||
$copy = $img->getChannels('green');
|
||||
$this->assertTrue($copy instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertFalse($copy->isTrueColor());
|
||||
$this->assertTrue($copy->isTransparent());
|
||||
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 0, 0);
|
||||
$this->assertEquals($copy->getTransparentColor(), $copy->getColorAt(50, 50));
|
||||
}
|
||||
|
||||
function testCopySingleChannel()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-rgbyg.png');
|
||||
|
||||
$copy = $img->getChannels('red');
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
$this->assertTrue($copy instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertTrue($copy->isTrueColor());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 255, 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 255, 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(50, 50), 127, 0, 0, 0);
|
||||
/*
|
||||
$copy = $img->copyChannels('green');
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
$this->assertTrue($copy instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertTrue($copy->isTrueColor());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(50, 50), 0, 127, 0);
|
||||
|
||||
$copy = $img->copyChannels('blue');
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
$this->assertTrue($copy instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertTrue($copy->isTrueColor());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(50, 50), 0, 0, 127);
|
||||
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$copy = $img->copyChannels('alpha');
|
||||
$this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 0, 0.25 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 0, 0.5 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 0, 0.75 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
*/
|
||||
}
|
||||
|
||||
function testCopyCombinedChannels()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$copy = $img->getChannels('blue', 'alpha');
|
||||
$this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 255, 0.25 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 255, 0.5 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 255, 0.75 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_GetMask_Test extends WideImage_TestCase
|
||||
{
|
||||
function testGetMaskTransparentGif()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$mask = $img->getMask();
|
||||
$this->assertTrue($mask instanceof WideImage_TrueColorImage);
|
||||
|
||||
$this->assertFalse($mask->isTransparent());
|
||||
$this->assertEquals(100, $mask->getWidth());
|
||||
$this->assertEquals(100, $mask->getHeight());
|
||||
|
||||
$this->assertRGBNear($mask->getRGBAt(10, 10), 255, 255, 255);
|
||||
$this->assertRGBNear($mask->getRGBAt(90, 90), 255, 255, 255);
|
||||
$this->assertRGBNear($mask->getRGBAt(50, 50), 0, 0, 0);
|
||||
}
|
||||
|
||||
function testGetMaskPNGAlpha()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
|
||||
$mask = $img->getMask();
|
||||
$this->assertTrue($mask instanceof WideImage_TrueColorImage);
|
||||
|
||||
$this->assertFalse($mask->isTransparent());
|
||||
$this->assertEquals(100, $mask->getWidth());
|
||||
$this->assertEquals(100, $mask->getHeight());
|
||||
|
||||
$this->assertRGBNear($mask->getRGBAt(25, 25), 192, 192, 192);
|
||||
$this->assertRGBNear($mask->getRGBAt(75, 25), 128, 128, 128);
|
||||
$this->assertRGBNear($mask->getRGBAt(75, 75), 64, 64, 64);
|
||||
$this->assertRGBNear($mask->getRGBAt(25, 75), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_Merge_Test extends WideImage_TestCase
|
||||
{
|
||||
function testMergeOpacityZero()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.png');
|
||||
$overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
|
||||
|
||||
$res = $img->merge($overlay, 0, 0, 0);
|
||||
|
||||
$this->assertEquals(100, $res->getWidth());
|
||||
$this->assertEquals(100, $res->getHeight());
|
||||
|
||||
$rgb = $res->getRGBAt(5, 5);
|
||||
$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 0, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 40, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 255, 'blue' => 0, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 60, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 40, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
|
||||
}
|
||||
|
||||
function testMergeOpacityHalf()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.png');
|
||||
$overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
|
||||
|
||||
$res = $img->merge($overlay, 0, 0, 50);
|
||||
|
||||
$this->assertEquals(100, $res->getWidth());
|
||||
$this->assertEquals(100, $res->getHeight());
|
||||
|
||||
$rgb = $res->getRGBAt(5, 5);
|
||||
$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 127, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 40, 40, array('red' => 127, 'green' => 127, 'blue' => 127, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 127, 'blue' => 0, 'alpha' => 0));
|
||||
|
||||
// these two should definitely pass ...
|
||||
|
||||
#$this->assertRGBAt($res, 60, 60, array('red' => 127, 'green' => 127, 'blue' => 127, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
|
||||
#$this->assertRGBAt($res, 40, 60, array('red' => 255, 'green' => 127, 'blue' => 127, 'alpha' => 0));
|
||||
}
|
||||
|
||||
function testMergeOpacityFull()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.png');
|
||||
$overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
|
||||
|
||||
$res = $img->merge($overlay, 0, 0, 100);
|
||||
|
||||
$this->assertEquals(100, $res->getWidth());
|
||||
$this->assertEquals(100, $res->getHeight());
|
||||
|
||||
$rgb = $res->getRGBAt(5, 5);
|
||||
$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 40, 40, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 60, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 40, 60, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_Mirror_Test extends WideImage_TestCase
|
||||
{
|
||||
function testMirror()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$this->assertRGBEqual($img->getRGBAt(5, 5), 255, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(95, 5), 0, 0, 255);
|
||||
$this->assertRGBEqual($img->getRGBAt(95, 95), 0, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(5, 95), 255, 0, 0);
|
||||
|
||||
$new = $img->mirror();
|
||||
|
||||
$this->assertTrue($new instanceof WideImage_PaletteImage);
|
||||
|
||||
$this->assertEquals(100, $new->getWidth());
|
||||
$this->assertEquals(100, $new->getHeight());
|
||||
|
||||
$this->assertRGBEqual($new->getRGBAt(95, 5), 255, 255, 0);
|
||||
$this->assertRGBEqual($new->getRGBAt(5, 5), 0, 0, 255);
|
||||
$this->assertRGBEqual($new->getRGBAt(5, 95), 0, 255, 0);
|
||||
$this->assertRGBEqual($new->getRGBAt(95, 95), 255, 0, 0);
|
||||
|
||||
$this->assertTrue($new->isTransparent());
|
||||
$this->assertRGBEqual($new->getRGBAt(50, 50), $img->getTransparentColorRGB());
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
WideImage_OperationFactory::get('ResizeCanvas');
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_ResizeCanvas_Test extends WideImage_TestCase
|
||||
{
|
||||
function testResizeCanvasUp()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(160, 120);
|
||||
$resized = $img->resizeCanvas(180, 180, 0, 0);
|
||||
$this->assertDimensions($resized, 180, 180);
|
||||
}
|
||||
|
||||
function testResizeCanvasDown()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(160, 120);
|
||||
$resized = $img->resizeCanvas(30, 100, 0, 0);
|
||||
$this->assertDimensions($resized, 30, 100);
|
||||
}
|
||||
|
||||
function testResizeCanvasPositionsCenter()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(20, 20);
|
||||
$black = $img->allocateColor(0, 0, 0);
|
||||
$white = $img->allocateColor(255, 255, 255);
|
||||
$img->fill(0, 0, $black);
|
||||
|
||||
$res = $img->resizeCanvas(40, 40, 'center', 'center', $white);
|
||||
$this->assertRGBAt($res, 5, 5, $white);
|
||||
$this->assertRGBAt($res, 35, 35, $white);
|
||||
$this->assertRGBAt($res, 5, 35, $white);
|
||||
$this->assertRGBAt($res, 35, 5, $white);
|
||||
$this->assertRGBAt($res, 20, 20, $black);
|
||||
}
|
||||
|
||||
function testResizeCanvasPositionsCorner()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(20, 20);
|
||||
$black = $img->allocateColor(0, 0, 0);
|
||||
$white = $img->allocateColor(255, 255, 255);
|
||||
$img->fill(0, 0, $black);
|
||||
|
||||
$res = $img->resizeCanvas(40, 40, 'bottom', 'right', $white);
|
||||
$this->assertRGBAt($res, 5, 5, $white);
|
||||
$this->assertRGBAt($res, 35, 35, $black);
|
||||
$this->assertRGBAt($res, 5, 35, $white);
|
||||
$this->assertRGBAt($res, 35, 5, $white);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
WideImage_OperationFactory::get('Resize');
|
||||
|
||||
class WideImage_Operation_Resize_Testable extends WideImage_Operation_Resize
|
||||
{
|
||||
function prepareDimensions($img, $width, $height, $fit)
|
||||
{
|
||||
return parent::prepareDimensions($img, $width, $height, $fit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_Resize_Test extends WideImage_TestCase
|
||||
{
|
||||
function testProxyMethod()
|
||||
{
|
||||
$op = $this->getMock('WideImage_Operation_Resize', array('execute'));
|
||||
$img = $this->getMock('WideImage_PaletteImage', array('getOperation'), array(imagecreate(10, 10)));
|
||||
|
||||
$img->expects($this->exactly(2))->
|
||||
method('getOperation')->with('Resize')->
|
||||
will($this->returnValue($op));
|
||||
|
||||
$op->expects($this->at(0))->
|
||||
method('execute')->with($img, 'WIDTH', 'HEIGHT', 'FIT', 'SCALE');
|
||||
|
||||
$op->expects($this->at(1))->
|
||||
method('execute')->with($img, null, null, 'inside', 'any');
|
||||
|
||||
$img->resize('WIDTH', 'HEIGHT', 'FIT', 'SCALE');
|
||||
$img->resize();
|
||||
}
|
||||
|
||||
function testResultTypeIsSameAsInput()
|
||||
{
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", WideImage::createPaletteImage(20, 20)->resize(10, 10));
|
||||
$this->assertInstanceOf("WideImage_TrueColorImage", WideImage::createTrueColorImage(20, 20)->resize(10, 10));
|
||||
}
|
||||
|
||||
function testResizeWithoutParametersDoesNothing()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(70, 20);
|
||||
$res = $img->resize();
|
||||
$this->assertDimensions($res, $img->getWidth(), $img->getHeight());
|
||||
}
|
||||
|
||||
function testPreservesTransparency()
|
||||
{
|
||||
$img = $this->load('100x100-color-hole.gif');
|
||||
$this->assertTrue($img->isTransparent());
|
||||
$res = $img->resize(50, 50);
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorMatch($img, $res);
|
||||
$this->assertEquals($res->getColorAt(25, 25), $res->getTransparentColor());
|
||||
}
|
||||
|
||||
function testFitFill()
|
||||
{
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'fill'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 30, 'fill'), 120, 30);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(20, 130, 'fill'), 20, 130);
|
||||
}
|
||||
|
||||
function testFitOutside()
|
||||
{
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'outside'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 30, 'outside'), 120, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(20, 30, 'outside'), 60, 30);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(20, 100, 'outside'), 200, 100);
|
||||
}
|
||||
|
||||
function testFitInside()
|
||||
{
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'inside'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 30, 'inside'), 60, 30);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(20, 30, 'inside'), 20, 10);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(20, 100, 'inside'), 20, 10);
|
||||
}
|
||||
|
||||
function testScaleDown()
|
||||
{
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'fill', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 60, 'fill', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 40, 'fill', 'down'), 120, 40);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 60, 'fill', 'down'), 90, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 30, 'fill', 'down'), 90, 30);
|
||||
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'inside', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 60, 'inside', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 40, 'inside', 'down'), 80, 40);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 60, 'inside', 'down'), 90, 45);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 30, 'inside', 'down'), 60, 30);
|
||||
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'outside', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 60, 'outside', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 40, 'outside', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 60, 'outside', 'down'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 30, 'outside', 'down'), 90, 45);
|
||||
}
|
||||
|
||||
function testScaleUp()
|
||||
{
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'fill', 'up'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 60, 'fill', 'up'), 120, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 40, 'fill', 'up'), 120, 40);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 60, 'fill', 'up'), 90, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 30, 'fill', 'up'), 100, 50);
|
||||
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'inside', 'up'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 60, 'inside', 'up'), 120, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 40, 'inside', 'up'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 60, 'inside', 'up'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 30, 'inside', 'up'), 100, 50);
|
||||
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(100, 50, 'outside', 'up'), 100, 50);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 60, 'outside', 'up'), 120, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(120, 40, 'outside', 'up'), 120, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 60, 'outside', 'up'), 120, 60);
|
||||
$this->assertDimensions(WideImage::createPaletteImage(100, 50)->resize(90, 30, 'outside', 'up'), 100, 50);
|
||||
}
|
||||
|
||||
function testResizeFill()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$resized = $img->resize(50, 20, 'fill');
|
||||
$this->assertTrue($resized instanceof WideImage_Image);
|
||||
$this->assertTrue($resized->isTransparent());
|
||||
$this->assertEquals(50, $resized->getWidth());
|
||||
$this->assertEquals(20, $resized->getHeight());
|
||||
$this->assertRGBEqual($resized->getRGBAt(5, 5), 255, 255, 0);
|
||||
$this->assertRGBEqual($resized->getRGBAt(45, 5), 0, 0, 255);
|
||||
$this->assertRGBEqual($resized->getRGBAt(45, 15), 0, 255, 0);
|
||||
$this->assertRGBEqual($resized->getRGBAt(5, 15), 255, 0, 0);
|
||||
|
||||
$this->assertRGBEqual($resized->getRGBAt(25, 10), 255, 255, 255);
|
||||
$this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255);
|
||||
}
|
||||
|
||||
function testNullDimensionsAreCalculatedForFill()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(100, 50);
|
||||
$resized = $img->resize(30, null, 'fill');
|
||||
$this->assertEquals(30, $resized->getWidth());
|
||||
$this->assertEquals(15, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(100, 50);
|
||||
$resized = $img->resize(null, 30, 'fill');
|
||||
$this->assertEquals(60, $resized->getWidth());
|
||||
$this->assertEquals(30, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(100, 50);
|
||||
$resized = $img->resize(30, 30, 'fill');
|
||||
$this->assertEquals(30, $resized->getWidth());
|
||||
$this->assertEquals(30, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(100, 50);
|
||||
$resized = $img->resize(30, 40, 'fill');
|
||||
$this->assertEquals(30, $resized->getWidth());
|
||||
$this->assertEquals(40, $resized->getHeight());
|
||||
}
|
||||
|
||||
function testResizeInside()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$resized = $img->resize(50, 20, 'inside');
|
||||
$this->assertTrue($resized instanceof WideImage_Image);
|
||||
$this->assertTrue($resized->isTransparent());
|
||||
$this->assertEquals(20, $resized->getWidth());
|
||||
$this->assertEquals(20, $resized->getHeight());
|
||||
/*
|
||||
$this->assertRGBEqual($resized->getRGBAt(5, 5), 255, 255, 0);
|
||||
$this->assertRGBEqual($resized->getRGBAt(45, 5), 0, 0, 255);
|
||||
$this->assertRGBEqual($resized->getRGBAt(45, 15), 0, 255, 0);
|
||||
$this->assertRGBEqual($resized->getRGBAt(5, 15), 255, 0, 0);
|
||||
$this->assertRGBEqual($resized->getRGBAt(25, 10), 255, 255, 255);
|
||||
$this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255);
|
||||
*/
|
||||
}
|
||||
|
||||
function testResizeDown()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(100, 100);
|
||||
$resized = $img->resizeDown(30);
|
||||
$this->assertEquals(30, $resized->getWidth());
|
||||
$this->assertEquals(30, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeDown(100);
|
||||
$this->assertEquals(100, $resized->getWidth());
|
||||
$this->assertEquals(50, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeDown(null, 30);
|
||||
$this->assertEquals(60, $resized->getWidth());
|
||||
$this->assertEquals(30, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeDown(201);
|
||||
$this->assertEquals($img->getWidth(), $resized->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeDown(null, 300);
|
||||
$this->assertEquals($img->getWidth(), $resized->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $resized->getHeight());
|
||||
}
|
||||
|
||||
function testResizeUp()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(100, 100);
|
||||
$resized = $img->resizeUp(300);
|
||||
$this->assertEquals(300, $resized->getWidth());
|
||||
$this->assertEquals(300, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeUp(300);
|
||||
$this->assertEquals(300, $resized->getWidth());
|
||||
$this->assertEquals(150, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(20, 10);
|
||||
$resized = $img->resizeUp(null, 30);
|
||||
$this->assertEquals(60, $resized->getWidth());
|
||||
$this->assertEquals(30, $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeUp(199);
|
||||
$this->assertEquals($img->getWidth(), $resized->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $resized->getHeight());
|
||||
|
||||
$img = WideImage_TrueColorImage::create(200, 100);
|
||||
$resized = $img->resizeUp(null, 10);
|
||||
$this->assertEquals($img->getWidth(), $resized->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $resized->getHeight());
|
||||
}
|
||||
|
||||
function testResizeBug214()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(1600, 1200);
|
||||
$resized = $img->resize(214, null, 'outside');
|
||||
$this->assertEquals(214, $resized->getWidth());
|
||||
$this->assertEquals(161, $resized->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_Rotate_Test extends WideImage_TestCase
|
||||
{
|
||||
function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagerotate'));
|
||||
}
|
||||
|
||||
function testRotateAlphaSafe()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$this->assertRGBEqual($img->getRGBAt(25, 25), 0, 0, 255, round(128 / 4));
|
||||
$this->assertRGBEqual($img->getRGBAt(75, 25), 0, 0, 255, round(2 * 128 / 4));
|
||||
$this->assertRGBEqual($img->getRGBAt(75, 75), 0, 0, 255, round(3 * 128 / 4));
|
||||
$this->assertRGBEqual($img->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
$new = $img->rotate(90, null);
|
||||
$this->assertEquals(100, $new->getWidth());
|
||||
$this->assertEquals(100, $new->getHeight());
|
||||
}
|
||||
|
||||
function testRotateCounterClockwise90()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$new = $img->rotate(-90);
|
||||
$this->assertEquals(287, $new->getWidth());
|
||||
$this->assertEquals(174, $new->getHeight());
|
||||
}
|
||||
|
||||
function testRotate45()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-rainbow.png');
|
||||
$new = $img->rotate(45);
|
||||
$this->assertEquals(142, $new->getWidth());
|
||||
$this->assertEquals(142, $new->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_RoundCorners_Test extends WideImage_TestCase
|
||||
{
|
||||
function testWhiteCorner()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.png');
|
||||
$res = $img->roundCorners(30, $img->allocateColor(255, 255, 255), WideImage::SIDE_ALL);
|
||||
|
||||
$this->assertEquals(100, $res->getWidth());
|
||||
$this->assertEquals(100, $res->getHeight());
|
||||
|
||||
$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 95, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 95, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
|
||||
$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
|
||||
}
|
||||
|
||||
function testTransparentCorner()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$res = $img->roundCorners(30, null, WideImage::SIDE_ALL);
|
||||
|
||||
$this->assertEquals(100, $res->getWidth());
|
||||
$this->assertEquals(100, $res->getHeight());
|
||||
|
||||
$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 95, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 95, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
|
||||
$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_Unsharp_Test extends WideImage_TestCase
|
||||
{
|
||||
function test()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$result = $img->unsharp(10, 5, 1);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_MyOperation
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_OperationFactory_Test extends WideImage_TestCase
|
||||
{
|
||||
function testFactoryReturnsCached()
|
||||
{
|
||||
$op1 = WideImage_OperationFactory::get('Mirror');
|
||||
$op2 = WideImage_OperationFactory::get('Mirror');
|
||||
$this->assertSame($op1, $op2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_UnknownImageOperationException
|
||||
*/
|
||||
function testNoOperation()
|
||||
{
|
||||
$op = WideImage_OperationFactory::get('NoSuchOp');
|
||||
}
|
||||
|
||||
function testUserDefinedOp()
|
||||
{
|
||||
$op = WideImage_OperationFactory::get('MyOperation');
|
||||
$this->assertTrue($op instanceof WideImage_Operation_MyOperation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_PaletteImage_Test extends WideImage_TestCase
|
||||
{
|
||||
function testCreate()
|
||||
{
|
||||
$img = WideImage_PaletteImage::create(10, 10);
|
||||
$this->assertTrue($img instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
$this->assertFalse($img->isTrueColor());
|
||||
}
|
||||
|
||||
function testCopy()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->assertTrue($img instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
$this->assertFalse($img->isTrueColor());
|
||||
$this->assertTrue($img->isTransparent());
|
||||
$this->assertRGBEqual($img->getRGBAt(15, 15), 255, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(85, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($img->getRGBAt(85, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(15, 85), 255, 0, 0);
|
||||
$this->assertTrue($img->getTransparentColor() === $img->getColorAt(50, 50));
|
||||
|
||||
$copy = $img->copy();
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
|
||||
$this->assertTrue($copy instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertFalse($copy->isTrueColor());
|
||||
$this->assertTrue($copy->isTransparent());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0);
|
||||
$this->assertTrue($copy->getTransparentColor() === $copy->getColorAt(50, 50));
|
||||
|
||||
$this->assertSame($img->getTransparentColorRGB(), $copy->getTransparentColorRGB());
|
||||
}
|
||||
|
||||
function testAsTrueColor()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->assertTrue($img instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
|
||||
$copy = $img->asTrueColor();
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
|
||||
$this->assertTrue($copy instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertTrue($copy->isTrueColor());
|
||||
$this->assertTrue($copy->isTransparent());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0);
|
||||
|
||||
$this->assertEquals($copy->getRGBAt(50, 50), $copy->getTransparentColorRGB());
|
||||
$rgb = $copy->getTransparentColorRGB();
|
||||
$this->assertRGBEqual($img->getTransparentColorRGB(), $rgb['red'], $rgb['green'], $rgb['blue']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_TrueColorImage_Test extends WideImage_TestCase
|
||||
{
|
||||
function testCreate()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$this->assertTrue($img instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
}
|
||||
|
||||
function testCopy()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-rgbyg.png');
|
||||
$this->assertTrue($img instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
$this->assertRGBEqual($img->getRGBAt(15, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($img->getRGBAt(85, 15), 255, 0, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(85, 85), 255, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(15, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($img->getRGBAt(50, 50), 127, 127, 127);
|
||||
|
||||
$copy = $img->copy();
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
|
||||
$this->assertTrue($copy instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertTrue($copy->isTrueColor());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 255, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 255, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(50, 50), 127, 127, 127);
|
||||
}
|
||||
|
||||
function testCopyAlphaGetsCopied()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
$this->assertTrue($img instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
$this->assertRGBNear($img->getRGBAt(25, 25), 0, 0, 255, 0.25 * 127);
|
||||
$this->assertRGBNear($img->getRGBAt(75, 25), 0, 0, 255, 0.5 * 127);
|
||||
$this->assertRGBNear($img->getRGBAt(75, 75), 0, 0, 255, 0.75 * 127);
|
||||
$this->assertRGBNear($img->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
|
||||
$copy = $img->copy();
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
|
||||
$this->assertTrue($copy instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertTrue($copy->isTrueColor());
|
||||
$this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 255, 0.25 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 255, 0.5 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 255, 0.75 * 127);
|
||||
$this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
}
|
||||
|
||||
function testAsPalette()
|
||||
{
|
||||
if (function_exists('imagecolormatch'))
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-rgbyg.png');
|
||||
$this->assertTrue($img instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($img->isValid());
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
|
||||
$copy = $img->asPalette();
|
||||
$this->assertFalse($img->getHandle() === $copy->getHandle());
|
||||
|
||||
$this->assertTrue($copy instanceof WideImage_PaletteImage);
|
||||
$this->assertTrue($copy->isValid());
|
||||
$this->assertFalse($copy->isTrueColor());
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 15), 0, 0, 255);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 15), 255, 0, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(85, 85), 255, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(15, 85), 0, 255, 0);
|
||||
$this->assertRGBEqual($copy->getRGBAt(50, 50), 127, 127, 127);
|
||||
}
|
||||
}
|
||||
|
||||
function testPreserveTransparency()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->assertTrue($img->isTransparent());
|
||||
$this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255);
|
||||
|
||||
$tc = $img->asTrueColor();
|
||||
$this->assertTrue($tc->isTransparent());
|
||||
$this->assertRGBEqual($tc->getTransparentColorRGB(), 255, 255, 255);
|
||||
|
||||
$img = $tc->asPalette();
|
||||
$this->assertTrue($img->isTransparent());
|
||||
$this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_FOO
|
||||
{
|
||||
public static $calls = array();
|
||||
public static $handle = null;
|
||||
|
||||
static function reset()
|
||||
{
|
||||
self::$calls = array();
|
||||
self::$handle = null;
|
||||
}
|
||||
|
||||
function load()
|
||||
{
|
||||
self::$calls['load'] = func_get_args();
|
||||
return self::$handle;
|
||||
}
|
||||
|
||||
function loadFromString($data)
|
||||
{
|
||||
self::$calls['loadFromString'] = func_get_args();
|
||||
return self::$handle;
|
||||
}
|
||||
|
||||
function save($image, $uri = null)
|
||||
{
|
||||
self::$calls['save'] = func_get_args();
|
||||
if ($uri == null)
|
||||
echo 'out';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class WideImage_Mapper_FOO2
|
||||
{
|
||||
public static $calls = array();
|
||||
|
||||
static function reset()
|
||||
{
|
||||
self::$calls = array();
|
||||
}
|
||||
|
||||
function load()
|
||||
{
|
||||
self::$calls['load'] = func_get_args();
|
||||
return false;
|
||||
}
|
||||
|
||||
function loadFromString($data)
|
||||
{
|
||||
self::$calls['loadFromString'] = func_get_args();
|
||||
}
|
||||
|
||||
function save($image, $uri = null)
|
||||
{
|
||||
self::$calls['save'] = func_get_args();
|
||||
if ($uri == null)
|
||||
echo 'out';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $_FILES;
|
||||
function setup()
|
||||
{
|
||||
$this->_FILES = $_FILES;
|
||||
$_FILES = array();
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$_FILES = $this->_FILES;
|
||||
|
||||
if (PHP_OS == 'WINNT')
|
||||
{
|
||||
chdir(IMG_PATH . "temp");
|
||||
|
||||
foreach (new DirectoryIterator(IMG_PATH . "temp") as $file)
|
||||
if (!$file->isDot())
|
||||
if ($file->isDir())
|
||||
exec("rd /S /Q {$file->getFilename()}\n");
|
||||
else
|
||||
unlink($file->getFilename());
|
||||
}
|
||||
else
|
||||
exec("rm -rf " . IMG_PATH . 'temp/*');
|
||||
}
|
||||
|
||||
function testLoadFromFile()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-red-transparent.gif');
|
||||
$this->assertTrue($img instanceof WideImage_PaletteImage);
|
||||
$this->assertValidImage($img);
|
||||
$this->assertFalse($img->isTrueColor());
|
||||
$this->assertEquals(100, $img->getWidth());
|
||||
$this->assertEquals(100, $img->getHeight());
|
||||
|
||||
$img = WideImage::load(IMG_PATH . '100x100-rainbow.png');
|
||||
$this->assertTrue($img instanceof WideImage_TrueColorImage);
|
||||
$this->assertValidImage($img);
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
$this->assertEquals(100, $img->getWidth());
|
||||
$this->assertEquals(100, $img->getHeight());
|
||||
}
|
||||
|
||||
function testLoadFromString()
|
||||
{
|
||||
$img = WideImage::load(file_get_contents(IMG_PATH . '100x100-rainbow.png'));
|
||||
$this->assertTrue($img instanceof WideImage_TrueColorImage);
|
||||
$this->assertValidImage($img);
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
$this->assertEquals(100, $img->getWidth());
|
||||
$this->assertEquals(100, $img->getHeight());
|
||||
}
|
||||
|
||||
function testLoadFromHandle()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH . '100x100-rainbow.png');
|
||||
$img = WideImage::loadFromHandle($handle);
|
||||
$this->assertValidImage($img);
|
||||
$this->assertTrue($img->isTrueColor());
|
||||
$this->assertSame($handle, $img->getHandle());
|
||||
$this->assertEquals(100, $img->getWidth());
|
||||
$this->assertEquals(100, $img->getHeight());
|
||||
unset($img);
|
||||
$this->assertFalse(WideImage::isValidImageHandle($handle));
|
||||
}
|
||||
|
||||
function testLoadFromUpload()
|
||||
{
|
||||
copy(IMG_PATH . '100x100-rainbow.png', IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg');
|
||||
$_FILES = array(
|
||||
'testupl' => array(
|
||||
'name' => '100x100-rainbow.png',
|
||||
'type' => 'image/png',
|
||||
'size' => strlen(file_get_contents(IMG_PATH . '100x100-rainbow.png')),
|
||||
'tmp_name' => IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg',
|
||||
'error' => false,
|
||||
)
|
||||
);
|
||||
|
||||
$img = WideImage::loadFromUpload('testupl');
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testLoadFromMultipleUploads()
|
||||
{
|
||||
copy(IMG_PATH . '100x100-rainbow.png', IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg1');
|
||||
copy(IMG_PATH . 'splat.tga', IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg2');
|
||||
$_FILES = array(
|
||||
'testupl' => array(
|
||||
'name' => array('100x100-rainbow.png', 'splat.tga'),
|
||||
'type' => array('image/png', 'image/tga'),
|
||||
'size' => array(
|
||||
strlen(file_get_contents(IMG_PATH . '100x100-rainbow.png')),
|
||||
strlen(file_get_contents(IMG_PATH . 'splat.tga'))
|
||||
),
|
||||
'tmp_name' => array(
|
||||
IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg1',
|
||||
IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg2'
|
||||
),
|
||||
'error' => array(false, false),
|
||||
)
|
||||
);
|
||||
|
||||
$images = WideImage::loadFromUpload('testupl');
|
||||
$this->assertInternalType("array", $images);
|
||||
$this->assertValidImage($images[0]);
|
||||
$this->assertValidImage($images[1]);
|
||||
|
||||
$img = WideImage::loadFromUpload('testupl', 1);
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testLoadMagicalFromHandle()
|
||||
{
|
||||
$img = WideImage::load(imagecreatefrompng(IMG_PATH . '100x100-rainbow.png'));
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
|
||||
function testLoadMagicalFromBinaryString()
|
||||
{
|
||||
$img = WideImage::load(file_get_contents(IMG_PATH . '100x100-rainbow.png'));
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testLoadMagicalFromFile()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-rainbow.png');
|
||||
$this->assertValidImage($img);
|
||||
copy(IMG_PATH . '100x100-rainbow.png', IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg');
|
||||
$_FILES = array(
|
||||
'testupl' => array(
|
||||
'name' => 'fgnl.bmp',
|
||||
'type' => 'image/bmp',
|
||||
'size' => strlen(file_get_contents(IMG_PATH . 'fgnl.bmp')),
|
||||
'tmp_name' => IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg',
|
||||
'error' => false,
|
||||
)
|
||||
);
|
||||
$img = WideImage::load('testupl');
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testLoadFromStringWithCustomMapper()
|
||||
{
|
||||
$img = WideImage::loadFromString(file_get_contents(IMG_PATH . 'splat.tga'));
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testLoadFromFileWithInvalidExtension()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'actually-a-png.jpg');
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testLoadFromFileWithInvalidExtensionWithCustomMapper()
|
||||
{
|
||||
if (PHP_OS == 'WINNT')
|
||||
$this->markTestSkipped("For some reason, this test kills PHP my 32-bit Vista + PHP 5.3.1.");
|
||||
|
||||
$img = WideImage::loadFromFile(IMG_PATH . 'fgnl-bmp.jpg');
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidImageSourceException
|
||||
*/
|
||||
function testLoadFromStringEmpty()
|
||||
{
|
||||
WideImage::loadFromString('');
|
||||
}
|
||||
|
||||
function testLoadBMPMagicalFromUpload()
|
||||
{
|
||||
copy(IMG_PATH . 'fgnl.bmp', IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg');
|
||||
$_FILES = array(
|
||||
'testupl' => array(
|
||||
'name' => 'fgnl.bmp',
|
||||
'type' => 'image/bmp',
|
||||
'size' => strlen(file_get_contents(IMG_PATH . 'fgnl.bmp')),
|
||||
'tmp_name' => IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'upltmpimg',
|
||||
'error' => false,
|
||||
)
|
||||
);
|
||||
$img = WideImage::load('testupl');
|
||||
$this->assertValidImage($img);
|
||||
}
|
||||
|
||||
function testMapperLoad()
|
||||
{
|
||||
WideImage_Mapper_FOO::$handle = imagecreate(10, 10);
|
||||
$filename = IMG_PATH . '/image.foo';
|
||||
WideImage::registerCustomMapper('WideImage_Mapper_FOO', 'image/foo', 'foo');
|
||||
$img = WideImage::load($filename);
|
||||
$this->assertEquals(WideImage_Mapper_FOO::$calls['load'], array($filename));
|
||||
imagedestroy(WideImage_Mapper_FOO::$handle);
|
||||
}
|
||||
|
||||
function testLoadFromFileFallbackToLoadFromString()
|
||||
{
|
||||
WideImage_Mapper_FOO::$handle = imagecreate(10, 10);
|
||||
$filename = IMG_PATH . '/image-actually-foo.foo2';
|
||||
WideImage::registerCustomMapper('WideImage_Mapper_FOO', 'image/foo', 'foo');
|
||||
WideImage::registerCustomMapper('WideImage_Mapper_FOO2', 'image/foo2', 'foo2');
|
||||
$img = WideImage::load($filename);
|
||||
$this->assertEquals(WideImage_Mapper_FOO2::$calls['load'], array($filename));
|
||||
$this->assertEquals(WideImage_Mapper_FOO::$calls['loadFromString'], array(file_get_contents($filename)));
|
||||
imagedestroy(WideImage_Mapper_FOO::$handle);
|
||||
}
|
||||
|
||||
function testMapperSaveToFile()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$img->saveToFile('test.foo', '123', 789);
|
||||
$this->assertEquals(WideImage_Mapper_FOO::$calls['save'], array($img->getHandle(), 'test.foo', '123', 789));
|
||||
}
|
||||
|
||||
function testMapperAsString()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$str = $img->asString('foo', '123', 789);
|
||||
$this->assertEquals(WideImage_Mapper_FOO::$calls['save'], array($img->getHandle(), null, '123', 789));
|
||||
$this->assertEquals('out', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidImageSourceException
|
||||
*/
|
||||
function testInvalidImageFile()
|
||||
{
|
||||
WideImage::loadFromFile(IMG_PATH . 'fakeimage.png');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidImageSourceException
|
||||
*/
|
||||
function testEmptyString()
|
||||
{
|
||||
WideImage::load('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidImageSourceException
|
||||
*/
|
||||
function testInvalidImageStringData()
|
||||
{
|
||||
WideImage::loadFromString('asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidImageSourceException
|
||||
*/
|
||||
function testInvalidImageHandle()
|
||||
{
|
||||
WideImage::loadFromHandle(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidImageSourceException
|
||||
*/
|
||||
function testInvalidImageUploadField()
|
||||
{
|
||||
WideImage::loadFromUpload('xyz');
|
||||
}
|
||||
}
|
||||