mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-23 01:31:53 +02:00
adding new tests for resize
This commit is contained in:
64
test/CImageResizerByAspectRatioTest.php
Normal file
64
test/CImageResizerByAspectRatioTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageResizerByAspectRatioTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// No value set
|
||||||
|
array(null, 100, 100, null, null, null, null),
|
||||||
|
|
||||||
|
// Aspect ratio 1
|
||||||
|
array(1, 100, 100, null, null, 100, 100),
|
||||||
|
array(1, 100, 100, null, 100, 100, 100),
|
||||||
|
array(1, 100, 100, 100, null, 100, 100),
|
||||||
|
array(1, 100, 100, 100, 100, 100, 100),
|
||||||
|
|
||||||
|
// Aspect ratio 2
|
||||||
|
array(2, 100, 100, null, null, 100, 50),
|
||||||
|
array(2, 100, 100, null, 100, 200, 100),
|
||||||
|
array(2, 100, 100, 100, null, 100, 50),
|
||||||
|
array(2, 100, 100, 100, 100, 100, 50),
|
||||||
|
|
||||||
|
// Aspect ratio 0.5
|
||||||
|
array(1/2, 100, 100, null, null, 50, 100),
|
||||||
|
array(1/2, 100, 100, null, 100, 50, 100),
|
||||||
|
array(1/2, 100, 100, 100, null, 100, 200),
|
||||||
|
array(1/2, 100, 100, 100, 100, 50, 100),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize1($aspectRatio, $srcWidth, $srcHeight, $targetWidth, $targetHeight, $expectedWidth, $expectedHeight)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'*/);
|
||||||
|
//$img = new CImageResizer('logger');
|
||||||
|
|
||||||
|
$img->setSource($srcWidth, $srcHeight)
|
||||||
|
->setBaseWidthHeight($targetWidth, $targetHeight)
|
||||||
|
->setBaseAspecRatio($aspectRatio)
|
||||||
|
->prepareTargetDimensions();
|
||||||
|
// ->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedWidth, $img->getTargetWidth(), "Width not correct.");
|
||||||
|
$this->assertEquals($expectedHeight, $img->getTargetHeight(), "Height not correct.");
|
||||||
|
}
|
||||||
|
}
|
65
test/CImageResizerByDensityPixelRatioTest.php
Normal file
65
test/CImageResizerByDensityPixelRatioTest.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageResizerByDevicePixelRatioTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// No value set
|
||||||
|
array(null, 100, 100, null, null, null, null),
|
||||||
|
|
||||||
|
// dpr 1
|
||||||
|
array(1, 100, 100, null, null, 100, 100),
|
||||||
|
array(1, 100, 100, null, 100, null, 100),
|
||||||
|
array(1, 100, 100, 100, null, 100, null),
|
||||||
|
array(1, 100, 100, 100, 100, 100, 100),
|
||||||
|
|
||||||
|
// dpr 2
|
||||||
|
array(2, 100, 100, null, null, 200, 200),
|
||||||
|
array(2, 100, 100, null, 200, null, 400),
|
||||||
|
array(2, 100, 100, 200, null, 400, null),
|
||||||
|
array(2, 100, 100, 200, 200, 400, 400),
|
||||||
|
|
||||||
|
// dpr 1/2
|
||||||
|
array(1/2, 100, 100, null, null, 50, 50),
|
||||||
|
array(1/2, 100, 100, null, 200, null, 100),
|
||||||
|
array(1/2, 100, 100, 200, null, 100, null),
|
||||||
|
array(1/2, 100, 100, 200, 200, 100, 100),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize1($dpr, $srcWidth, $srcHeight, $targetWidth, $targetHeight, $expectedWidth, $expectedHeight)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'*/);
|
||||||
|
//$img = new CImageResizer('logger');
|
||||||
|
|
||||||
|
$img->setSource($srcWidth, $srcHeight)
|
||||||
|
//->setResizeStrategy($img::KEEP_RATIO)
|
||||||
|
->setBaseWidthHeight($targetWidth, $targetHeight)
|
||||||
|
->setBaseDevicePixelRate($dpr)
|
||||||
|
->prepareTargetDimensions();
|
||||||
|
//->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedWidth, $img->getTargetWidth(), "Width not correct.");
|
||||||
|
$this->assertEquals($expectedHeight, $img->getTargetHeight(), "Height not correct.");
|
||||||
|
}
|
||||||
|
}
|
64
test/CImageResizerStrategyCropToFitTest.php
Normal file
64
test/CImageResizerStrategyCropToFitTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageResizerStrategyCropToFitTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// Square
|
||||||
|
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
||||||
|
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
||||||
|
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize1($srcWidth, $srcHeight, $targetWidth, $targetHeight, $targetWidthAfter, $targetHeightAfter, $cropX, $cropY, $cropWidth, $cropHeight)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($srcWidth, $srcHeight)
|
||||||
|
->setBaseWidthHeight($targetWidth, $targetHeight)
|
||||||
|
->setResizeStrategy(CImageResizer::CROP_TO_FIT)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($targetWidthAfter, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($targetHeightAfter, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cropX, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cropY, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cropWidth, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($cropHeight, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
|
}
|
64
test/CImageResizerStrategyFillToFitTest.php
Normal file
64
test/CImageResizerStrategyFillToFitTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageResizerStrategyFillToFitTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// Square
|
||||||
|
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
||||||
|
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
||||||
|
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize1($srcWidth, $srcHeight, $targetWidth, $targetHeight, $targetWidthAfter, $targetHeightAfter, $cropX, $cropY, $cropWidth, $cropHeight)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($srcWidth, $srcHeight)
|
||||||
|
->setBaseWidthHeight($targetWidth, $targetHeight)
|
||||||
|
->setResizeStrategy(CImageResizer::FILL_TO_FIT)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($targetWidthAfter, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($targetHeightAfter, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cropX, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cropY, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cropWidth, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($cropHeight, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
|
}
|
64
test/CImageResizerStrategyKeepAspectRatioTest.php
Normal file
64
test/CImageResizerStrategyKeepAspectRatioTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageResizerStrategyKeepAspectRatioTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// Square
|
||||||
|
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
||||||
|
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
||||||
|
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize1($sw, $sh, $tw, $th, $twa, $tha, $cx, $cy, $cw, $ch)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th)
|
||||||
|
->setResizeStrategy(CImageResizer::KEEP_RATIO)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($twa, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($tha, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
|
}
|
64
test/CImageResizerStrategyStretchTest.php
Normal file
64
test/CImageResizerStrategyStretchTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageResizerStrategyStretchTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// Square
|
||||||
|
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
||||||
|
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
||||||
|
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
||||||
|
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize1($sw, $sh, $tw, $th, $twa, $tha, $cx, $cy, $cw, $ch)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th)
|
||||||
|
->setResizeStrategy(CImageResizer::STRETCH)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($twa, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($tha, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user