File: 031_Imagick_affineTransformImage_basic.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 (146 lines) | stat: -rw-r--r-- 4,099 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
--TEST--
Test Imagick, affineTransformImage
--SKIPIF--
<?php
$imageMagickRequiredVersion=0x675;
require_once(dirname(__FILE__) . '/skipif.inc');
if (PHP_OS_FAMILY == 'Windows') die('skip dither is apparently borken on Windows https://github.com/Imagick/imagick/issues/590');
?>
--XFAIL--
I don't understand what values are returned in which elements of getImageChannelStatistics
--FILE--
<?php


function checkAllStatsAreValue($channelStatistics, $value) {

    if ($channelStatistics[Imagick::CHANNEL_RED]['mean'] != $value) {
        echo "Channel red is wrong " . $channelStatistics[Imagick::CHANNEL_RED]['mean'] . " vs " . $value. "\n";
    }
    if ($channelStatistics[Imagick::CHANNEL_GREEN]['mean'] != $value) {
        echo "Channel green is wrong " . $channelStatistics[Imagick::CHANNEL_GREEN]['mean'] . " vs " . $value. "\n";
    }
    if ($channelStatistics[Imagick::CHANNEL_BLUE]['mean'] != $value) {
        echo "Channel blue is wrong " . $channelStatistics[Imagick::CHANNEL_BLUE]['mean'] . " vs " . $value. "\n";
    }

    echo "Stats checked\n";
}

function affineTransformImage() {
    $imagick = new \Imagick();
    $imagick->newPseudoImage(640, 640, "xc:black");
    $draw = new \ImagickDraw();

    $angle = deg2rad(45);
    //$angle = deg2rad(3);

    $draw->setFillColor('white');
    $draw->setStrokeColor('white');
    $draw->setStrokeWidth(10.0);
    $draw->setStrokeLineCap(Imagick::LINECAP_SQUARE);
    $draw->setStrokeLineJoin(Imagick::LINEJOIN_BEVEL);

    $draw->line(
        $start_x = -50,
        $start_y = -50,
        $end_x = 690,
        $end_y = 690
    );

    $imagick->drawImage($draw);

    $draw = new \ImagickDraw();

    $affineRotate = array(
        "sx" => cos($angle), "sy" => cos($angle), 
        "rx" => sin($angle), "ry" => -sin($angle), 
        "tx" => 0, "ty" => 0,
    );

    $draw->affine($affineRotate);

    $imagick->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_BLACK);
    $imagick->affineTransformImage($draw);
    $imagick->setImagePage($imagick->getimageWidth(), $imagick->getimageheight(), 0, 0);

    $imagick->cropImage(
        $imagick->getImageWidth() - 40,
        $imagick->getImageHeight() - 40,
        20,
        20
    );

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


    $lineCheckBlack = clone $imagick;
    $blackout = new \ImagickDraw();
    $blackout->setStrokeColor('black');
    $blackout->setFillColor('black');
    $blackout->rectangle(
        ($lineCheckBlack->getImageWidth() / 2) - 20,
        0,
        ($lineCheckBlack->getImageWidth() / 2) + 20,
        $lineCheckBlack->getImageHeight()
    );

    $lineCheckBlack->drawImage($blackout);
    // $lineCheckBlack->writeImage(__DIR__ . '/test_031_blank.png');

    $whiteout = new \ImagickDraw();
    $lineCheckWhite = clone $imagick;
    $whiteout->setStrokeColor('white');
    $whiteout->setFillColor('white');
    $whiteout->rectangle(
        ($lineCheckBlack->getImageWidth() / 2) - 4,
        0,
        0,
        $lineCheckBlack->getImageHeight()
    );
    $whiteout->rectangle(
        ($lineCheckWhite->getImageWidth() / 2) + 4,
        0,
        $lineCheckWhite->getImageWidth(),
        $lineCheckWhite->getImageHeight()
    );

    $lineCheckWhite->drawImage($whiteout);
    // $lineCheckWhite->writeImage(__DIR__ . '/test_031_white.png');

    $channelStatistics = $lineCheckWhite->getImageChannelStatistics();

    echo "Checking white\n";
    checkAllStatsAreValue($channelStatistics, Imagick::getQuantum());


    $channelStatistics = $lineCheckBlack->getImageChannelStatistics();
//    var_dump(
//        "lineCheckBlack channel stats are:",
//        $channelStatistics
//    );

    echo "Checking black\n";
    checkAllStatsAreValue($channelStatistics, 0);

    $bytes = $imagick->getImageBlob();
    if (strlen($bytes) <= 0) { echo "Failed to generate image.";}
}

affineTransformImage() ;
echo "Ok";
?>
--CLEAN--
<?php
$f = __DIR__ . "/test_031.png";
if (file_exists($f)) {
    @unlink($f);
}
?>
--EXPECTF--
Checking white
Stats checked
Checking black
Stats checked
Ok