<?php
use Grafika\Color;
use Grafika\EditorInterface;
use Grafika\Gd\Editor;
use Grafika\Gd\Filter\Blur;
use Grafika\Gd\Filter\Brightness;
use Grafika\Gd\Filter\Colorize;
use Grafika\Gd\Image;
use Grafika\Grafika;
use Grafika\Position;
class GdEditorTest extends PHPUnit_Framework_TestCase
{
protected $dirAssert = DIR_ASSERT_GD;
public function testCreateEditor()
{
$editor = new \Grafika\Gd\Editor(); $this->assertTrue($editor instanceof EditorInterface);
return $editor;
}
public function testCreateEditorStatic()
{
Grafika::setEditorList(array('Gd'));
$editor = Grafika::createEditor();
$this->assertTrue($editor instanceof EditorInterface);
}
public function testOpenFail(EditorInterface $editor)
{
if (version_compare(PHP_VERSION, '5.6', '>=')) {
$this->expectException('\Exception');
$input = 'unreachable.jpg';
Grafika::createImage($input);
}
}
public function testUnknownTypeFail($editor)
{
if (version_compare(PHP_VERSION, '5.6', '>=')) {
$this->expectException('\Exception');
$input = DIR_TEST_IMG . '/unsupported.bmp';
Grafika::createImage($input);
}
}
public function testOpenJpeg($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$image = Grafika::createImage($input);
$this->assertTrue($image instanceof Image);
}
public function testOpenPng($editor)
{
$input = DIR_TEST_IMG . '/sample.png';
$image = Grafika::createImage($input);
$this->assertTrue($image instanceof Image);
}
public function testOpenGif($editor)
{
$input = DIR_TEST_IMG . '/sample.gif';
$image = Grafika::createImage($input);
$this->assertTrue($image instanceof Image);
}
public function testOpenWbmp($editor)
{
$input = DIR_TEST_IMG . '/sample.wbm';
$image = Grafika::createImage($input);
$this->assertTrue($image instanceof Image);
}
public function testEqual($editor)
{
$input1 = $this->dirAssert . '/testEqual.jpg';
$this->assertTrue($editor->equal($input1, $input1));
return $editor;
}
public function testEqualFalse($editor)
{
$input1 = $this->dirAssert . '/testEqual.jpg';
$input2 = $this->dirAssert . '/testEqualFalse.png';
$this->assertFalse($editor->equal($input1, $input2));
return $editor;
}
public function testCompare($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$input2 = DIR_TEST_IMG . '/lena-gray.png';
$ham = $editor->compare($input,$input2);
$this->assertLessThan(10,$ham); }
public function testSave($editor){
$input = DIR_TEST_IMG . '/sample.png';
$output1 = DIR_TMP . '/' . __FUNCTION__ . '1.jpg';
$output2 = DIR_TMP . '/' . __FUNCTION__ . '2.jpg';
$output3 = DIR_TMP . '/' . __FUNCTION__ . '3.png';
$image = Grafika::createImage($input);
$editor->save($image, $output1, 'jpg', 100);
$this->assertEquals(0, $editor->compare($input, $output1));
$editor->save($image, $output2, 'jpg', 0);
$this->assertGreaterThan(0, $editor->compare($input, $output2));
$editor->save($image, $output3, 'png', null);
$this->assertEquals(0, $editor->compare($input, $output3));
}
public function testAddTextOnBlankImage($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$blank = Grafika::createBlankImage( 400, 100 );
$editor->fill( $blank, new Color( '#ffffff' ) );
$editor->text( $blank, 'Lorem ipsum - Liberation Sans');
$editor->save( $blank, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testAddTextOnJpeg($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeFit($image, 300, 300);
$editor->text($image, 'Lorem ipsum - Liberation Sans');
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testResizeFitEnlarge($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeFit($image, $image->getWidth() + 100, $image->getHeight() + 100);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
$input = DIR_TEST_IMG . '/sample.gif';
$output = DIR_TMP . '/' . __FUNCTION__ . '.gif';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.gif';
$image = Grafika::createImage($input);
$editor->resizeFit($image, $image->getWidth() + 100, $image->getHeight() + 100);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testResizeFitPortrait($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeFit($image, 200, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testResizeExact($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeExact($image, 200, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
$input = DIR_TEST_IMG . '/sample.gif';
$output = DIR_TMP . '/' . __FUNCTION__ . '.gif';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.gif';
$image = Grafika::createImage($input);
$editor->resizeExact($image, 200, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testResizeExactPortrait($editor)
{
$input = DIR_TEST_IMG . '/portrait.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeExact($image, 200, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testResizeFill($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeFill($image, 200, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testResizeFillPortrait($editor)
{
$input = DIR_TEST_IMG . '/portrait.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeFill($image, 200, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testResizeExactWidth($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeExactWidth($image, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testResizeExactWidthPortrait($editor)
{
$input = DIR_TEST_IMG . '/portrait.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeExactWidth($image, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testResizeExactHeight($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeExactHeight($image, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testResizeExactHeightPortrait($editor)
{
$input = DIR_TEST_IMG . '/portrait.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->resizeExactHeight($image, 200);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testRotate($editor)
{
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage($input);
$editor->rotate($image, 45);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct)); }
public function testCubicBezier($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createBlankImage( 277, 277 );
$editor->fill( $image, new Color( '#FFFFFF' ) );
$obj = Grafika::createDrawingObject('CubicBezier', array(42, 230), array(230, 237), array(42, 45), array(230, 43), new Color('#000000'));
$editor->draw($image, $obj);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testEllipse($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.png';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.png';
$image = Grafika::createBlankImage( 200, 200 );
$editor->fill( $image, new Color( '#FFFFFF' ) );
$obj = Grafika::createDrawingObject( 'Ellipse', 100, 50, array( 50, 75 ), 1, new Color( '#000000' ), new Color( '#FF0000' ) );
$editor->draw($image, $obj);
$editor->save($image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testLines($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createBlankImage( 200, 200 );
$editor->fill( $image, new Color( '#FFFFFF' ) );
$editor->draw( $image, Grafika::createDrawingObject('Line', array(0, 0), array(200, 200), 1, new Color('#FF0000')));
$editor->draw( $image, Grafika::createDrawingObject('Line', array(0, 200), array(200, 0), 1, new Color('#00FF00')));
$editor->draw( $image, Grafika::createDrawingObject('Line', array(0, 0), array(200, 100), 1, new Color('#0000FF')));
$editor->draw( $image, Grafika::createDrawingObject('Line', array(0, 100), array(200, 100)));
$editor->draw( $image, Grafika::createDrawingObject('Line', array(100, 0), array(100, 200)));
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($correct, $output));
}
public function testQuadraticBezier($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createBlankImage( 277, 277 );
$editor->fill( $image, new Color( '#EEEEEE' ) );
$obj = Grafika::createDrawingObject('QuadraticBezier', array(70, 250), array(20, 110), array(220, 60), new Color('#FF0000'));
$editor->draw( $image, $obj);
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testRectangle($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createBlankImage( 200, 200 );
$editor->fill( $image, new Color( '#CCCCCC' ) );
$editor->draw( $image, Grafika::createDrawingObject('Rectangle', 85, 50)); $editor->draw( $image, Grafika::createDrawingObject('Rectangle', 85, 50, array(105, 10), 0, null, new Color('#FF0000'))); $editor->draw( $image, Grafika::createDrawingObject('Rectangle', 85, 50, array(105, 70), 0, null, new Color('#00FF00'))); $editor->draw( $image, Grafika::createDrawingObject('Rectangle', 85, 50, array(0, 60), 1, '#000000', null));
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testPolygon($editor)
{
$output = DIR_TMP . '/' . __FUNCTION__ . '.png';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.png';
$image = Grafika::createBlankImage( 200, 200 );
$editor->fill( $image, new Color( '#FFFFFF' ) );
$editor->draw( $image, Grafika::createDrawingObject('Polygon', array(array(0,0), array(50,0), array(0,50)), 1));
$editor->draw( $image, Grafika::createDrawingObject('Polygon', array(array(200-1,0), array(150-1,0), array(200-1,50)), 1));
$editor->draw( $image, Grafika::createDrawingObject('Polygon', array(array(100,0), array(140,50), array(100,100), array(60,50)), 1, null, new Color('#FF0000')));
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testDither($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . 'Diffusion.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . 'Diffusion.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Dither', 'diffusion') );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . 'Ordered.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . 'Ordered.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Dither', 'ordered') );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testSobel($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Sobel') );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testBlur($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Blur', 10) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testBrightness($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, new Brightness(50) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testColorize($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, new Colorize(-50, -50, -50) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testContrast($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Contrast', 50) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testGamma($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Gamma', 2.0) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testGrayscale($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Grayscale') );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
$input = DIR_TEST_IMG . '/sample.gif';
$output = DIR_TMP . '/' . __FUNCTION__ . '.gif';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Grayscale') );
$editor->save( $image, $output);
$this->assertTrue($image->isAnimated());
}
public function testInvert($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Invert') );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testPixelate($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Pixelate',10) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testSharpen($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image = Grafika::createImage( $input );
$editor->apply( $image, Grafika::createFilter('Sharpen', 50) );
$editor->save( $image, $output);
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testCrop($editor)
{
$input = DIR_TEST_IMG . '/crop-test.jpg';
$output1 = DIR_TMP . '/' . __FUNCTION__ . '1.jpg';
$correct1 = $this->dirAssert . '/' . __FUNCTION__ . '1.jpg';
$output2 = DIR_TMP . '/' . __FUNCTION__ . '2.jpg';
$correct2 = $this->dirAssert . '/' . __FUNCTION__ . '2.jpg';
$output3 = DIR_TMP . '/' . __FUNCTION__ . '3.jpg';
$correct3 = $this->dirAssert . '/' . __FUNCTION__ . '3.jpg';
$output4 = DIR_TMP . '/' . __FUNCTION__ . '4.jpg';
$correct4 = $this->dirAssert . '/' . __FUNCTION__ . '4.jpg';
$output5 = DIR_TMP . '/' . __FUNCTION__ . '5.jpg';
$correct5 = $this->dirAssert . '/' . __FUNCTION__ . '5.jpg';
$output6 = DIR_TMP . '/' . __FUNCTION__ . '6.jpg';
$correct6 = $this->dirAssert . '/' . __FUNCTION__ . '6.jpg';
$output7 = DIR_TMP . '/' . __FUNCTION__ . '7.jpg';
$correct7 = $this->dirAssert . '/' . __FUNCTION__ . '7.jpg';
$output8 = DIR_TMP . '/' . __FUNCTION__ . '8.jpg';
$correct8 = $this->dirAssert . '/' . __FUNCTION__ . '8.jpg';
$output9 = DIR_TMP . '/' . __FUNCTION__ . '9.jpg';
$correct9 = $this->dirAssert . '/' . __FUNCTION__ . '9.jpg';
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'top-left' );
$editor->save( $image, $output1);
$this->assertLessThanOrEqual(5, $editor->compare($output1, $correct1));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'top-center' );
$editor->save( $image, $output2);
$this->assertLessThanOrEqual(5, $editor->compare($output2, $correct2));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'top-right' );
$editor->save( $image, $output3);
$this->assertLessThanOrEqual(5, $editor->compare($output3, $correct3));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'center-left' );
$editor->save( $image, $output4);
$this->assertLessThanOrEqual(5, $editor->compare($output4, $correct4));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'center' );
$editor->save( $image, $output5);
$this->assertLessThanOrEqual(5, $editor->compare($output5, $correct5));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'center-right' );
$editor->save( $image, $output6);
$this->assertLessThanOrEqual(5, $editor->compare($output6, $correct6));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'bottom-left' );
$editor->save( $image, $output7);
$this->assertLessThanOrEqual(5, $editor->compare($output7, $correct7));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'bottom-center' );
$editor->save( $image, $output8);
$this->assertLessThanOrEqual(5, $editor->compare($output8, $correct8));
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 150, 'bottom-right' );
$editor->save( $image, $output9);
$this->assertLessThanOrEqual(5, $editor->compare($output9, $correct9));
}
public function testSmartCrop($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '1.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '1.jpg';
$image = Grafika::createImage( $input );
$editor->crop( $image, 250, 250, 'smart' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($correct, $output));
$input = DIR_TEST_IMG . '/tower.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '2.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '2.jpg';
$image = Grafika::createImage( $input );
$editor->crop( $image, 260, 400, 'smart' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($correct, $output));
$input = DIR_TEST_IMG . '/portal-companion-cube.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '3.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '3.jpg';
$image = Grafika::createImage( $input );
$editor->crop( $image, 200, 200, 'smart' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($correct, $output));
$input = DIR_TEST_IMG . '/sample.jpg';
$output = DIR_TMP . '/' . __FUNCTION__ . '4.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '4.jpg';
$image = Grafika::createImage( $input );
$editor->crop( $image, 200, 200, 'smart' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($correct, $output));
$input = DIR_TEST_IMG . '/sample.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '5.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '5.jpg';
$image = Grafika::createImage( $input );
$editor->crop( $image, 200, 200, 'smart' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($correct, $output)); }
public function testFlattenAnimatedGif($editor)
{
$input = DIR_TEST_IMG . '/sample.gif';
$output = DIR_TMP . '/' . __FUNCTION__ . '.gif';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.gif';
$image = Grafika::createImage( $input );
$editor->flatten( $image );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testFlip($editor)
{
$input = DIR_TEST_IMG . '/lena.png';
$output = DIR_TMP . '/' . __FUNCTION__ . 'H.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . 'H.jpg';
$image = Grafika::createImage( $input );
$editor->flip( $image, 'h' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
$output = DIR_TMP . '/' . __FUNCTION__ . 'V.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . 'V.jpg';
$image = Grafika::createImage( $input );
$editor->flip( $image, 'v' );
$editor->save( $image, $output );
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
public function testBlend($editor)
{
$input1 = DIR_TEST_IMG . '/lena.png';
$input2 = DIR_TEST_IMG . '/blend.png';
$output = DIR_TMP . '/' . __FUNCTION__ . '.jpg';
$correct = $this->dirAssert . '/' . __FUNCTION__ . '.jpg';
$image1 = Grafika::createImage( $input1 );
$image2 = Grafika::createImage( $input2 );
$editor->blend( $image1, $image2, 'overlay', 0.5, 'center' ); $editor->save( $image1, $output );
$this->assertLessThanOrEqual(5, $editor->compare($output, $correct));
}
protected function setUp()
{
$editor = new Editor();
if (false === $editor->isAvailable()) {
$this->markTestSkipped(
'PHP GD is not available.'
);
}
}
protected function tearDown()
{
if (CLEAN_DUMP) {
deleteTmpDirectory(); }
}
public static function setUpBeforeClass()
{
}
public static function tearDownAfterClass()
{
}
}