imagick_smartcrop.test in Imagick 7
Tests for the smartcrop module.
File
imagick_smartcrop/imagick_smartcrop.testView source
<?php
/**
* @file
* Tests for the smartcrop module.
*/
class SmartcropImagickTestCase extends DrupalWebTestCase {
protected $admin_user;
public static function getInfo() {
return array(
'name' => t('Smartcrop Imagick test'),
'description' => t('Test Smartcrop Imagick.'),
'group' => t('Image'),
);
}
function setUp() {
parent::setUp();
module_enable(array(
'smartcrop',
));
}
/**
* Verify the entropy calculation with a known image.
*/
function testEntropy() {
// Create a test image with 3 red, 3 green, and 3 blue pixels.
$im = new Imagick();
$im
->newImage(3, 1, '#ff0000');
$im
->newImage(3, 1, '#00ff00');
$im
->newImage(3, 1, '#0000ff');
$im
->resetIterator();
$image = new stdClass();
$image->resource = $im
->appendImages(true);
// Calculate the expected values.
// There are 9 bins in the histogram, 3 colors * 3 channels.
$expected_entroy = (1 / 3 * log(1 / 9, 2) + 2 / 3 * log(2 / 9, 2)) * -1;
$image_entropy = _smartcrop_imagick_entropy_slice($image, 0, 0, 3, 3);
$this
->assertTrue($image_entropy - $expected_entroy < 0.001, t('Entropy value is correct.'));
}
}
Classes
Name | Description |
---|---|
SmartcropImagickTestCase | @file Tests for the smartcrop module. |