File: 274_imagick_setImageAlpha.phpt

package info (click to toggle)
php-imagick 3.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,288 kB
  • sloc: ansic: 17,876; php: 1,440; xml: 444; pascal: 80; sh: 19; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 1,937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--TEST--
Imagick::setImageAlpha
--SKIPIF--
<?php 
$imageMagickRequiredVersion=0x700;
require_once(dirname(__FILE__) . '/skipif.inc'); 
?>
--FILE--
<?php

require_once __DIR__ . "/../util/functions.php";

$imagick = new Imagick();
$imagick->newPseudoImage(256, 256, 'xc:purple');
$imagick->setImageAlpha(0.5);

$imagick->setImageFormat('png');
$imagick->writeImage(__DIR__ . "/setAlphaTest.png");

$pixelTypes = array(
	Imagick::PIXEL_CHAR => array(128, 0, 128, 128),
	Imagick::PIXEL_FLOAT => array(0.50196081399918, 0, 0.50196081399918, 0.5),
    Imagick::PIXEL_DOUBLE => array(0.50196078431373, 0, 0.50196078431373, 0.5),
	Imagick::PIXEL_SHORT => array(32896, 0, 32896, 32768),
);

function getColorError($type, $expected, $actual) {

    if ($type == Imagick::PIXEL_CHAR ||
        $type == Imagick::PIXEL_SHORT) {
        $string  = "Expected: " . $actual . "\n";
        $string .= "Actual  : " . $actual . "\n";

        return $string;
    }

    if ($type == Imagick::PIXEL_FLOAT) {
        return float_compare_32($expected, $actual);
    }

    if ($type == Imagick::PIXEL_DOUBLE) {
        return float_compare($expected, $actual);
    }

    echo "Unknown type: $type \n";
    exit(-1);
}


foreach ($pixelTypes as $pixelType => $expectedValues) {
	$pixels = $imagick->exportImagePixels(0, 0, 1, 1, "RGBA", $pixelType);
	$channelNames = ['R', 'G', 'B', 'A'];

	// Loop over the colours
	for ($channel = 0; $channel < 4; $channel++) {
		$actual = $pixels[$channel];
		$expected = $expectedValues[$channel];
		if (abs($actual - $expected) > get_epsilon_for_off_by_half_errors()) {
		    $channelName = $channelNames[$channel];

			echo "Pixel values appear incorrect for pixelType $pixelType channel:$channelName\n";
            echo getColorError($pixelType, $expected, $actual);
			break;
		}
	}
}

echo "Ok";

?>
--CLEAN--
<?php
$f = __DIR__ . '/setAlphaTest.png';
if (file_exists($f)) {
    @unlink($f);
}
?>
--EXPECTF--
Ok