function SmartcropTestCase::difference in Smart Crop 7
Same name and namespace in other branches
- 6 tests/smartcrop.test \SmartcropTestCase::difference()
Calculate the difference of 2 images.
Parameters
$image1 A GD image resource.:
$image2 A GD image resource.:
Return value
A GD image resource, with the subtracted image.
2 calls to SmartcropTestCase::difference()
- SmartcropTestCase::assertImageEqual in tests/
smartcrop.test - Assert that two images are the same, with some difference allowed to account for e.g. compression artifacts.
- SmartcropTestCase::assertImageNotEqual in tests/
smartcrop.test - Assert that two images are not the same, with some difference allowed to account for e.g. compression artifacts.
File
- tests/
smartcrop.test, line 231 - Tests for the smartcrop module.
Class
- SmartcropTestCase
- @file Tests for the smartcrop module.
Code
function difference($image1, $image2) {
$this
->assertEqual(imagesx($image1), imagesx($image2), t('Images have the same width.'));
$this
->assertEqual(imagesy($image1), imagesy($image2), t('Images have the same height.'));
$difference = imagecreatetruecolor(imagesx($image1), imagesy($image1));
for ($i = 0; $i < imagesx($image1); $i++) {
for ($j = 0; $j < imagesy($image1); $j++) {
$rgb1 = imagecolorat($image1, $i, $j);
$r1 = $rgb1 >> 16 & 0xff;
$g1 = $rgb1 >> 8 & 0xff;
$b1 = $rgb1 & 0xff;
$rgb2 = imagecolorat($image2, $i, $j);
$r2 = $rgb2 >> 16 & 0xff;
$g2 = $rgb2 >> 8 & 0xff;
$b2 = $rgb2 & 0xff;
imagesetpixel($difference, $i, $j, imagecolorallocate($difference, abs($r2 - $r1), abs($g2 - $g1), abs($b2 - $b1)));
}
}
return $difference;
}