xref: /php-src/ext/gd/tests/bug43475.phpt (revision 0b8466f2)
1--TEST--
2Bug #43475 (Thick styled lines have scrambled patterns)
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.2', '<')) {
8        die("skip test requires GD 2.2.2 or higher");
9    }
10    if (!(imagetypes() & IMG_PNG)) {
11        die("skip No PNG support");
12    }
13?>
14--FILE--
15<?php
16require_once __DIR__ . '/similarity.inc';
17
18function setStyleAndThickness($im, $color, $thickness)
19{
20    $style = array();
21    $i = 0;
22    while ($i < 16 * $thickness) {
23        $style[$i++] = $color;
24    }
25    while ($i < 20 * $thickness) {
26        $style[$i++] = IMG_COLOR_TRANSPARENT;
27    }
28    while ($i < 28 * $thickness) {
29        $style[$i++] = $color;
30    }
31    while ($i < 32 * $thickness) {
32        $style[$i++] = IMG_COLOR_TRANSPARENT;
33    }
34    imagesetstyle($im, $style);
35    imagesetthickness($im, $thickness);
36}
37
38$im = imagecreate(800, 800);
39imagecolorallocate($im, 255, 255, 255);
40$black = imagecolorallocate($im, 0, 0, 0);
41
42setStyleAndThickness($im, $black, 1);
43imageline($im,  50, 250, 550, 250, IMG_COLOR_STYLED);
44imageline($im, 550, 250, 550, 750, IMG_COLOR_STYLED);
45imageline($im, 550, 750,  50, 250, IMG_COLOR_STYLED);
46
47setStyleAndThickness($im, $black, 2);
48imageline($im, 100, 200, 600, 200, IMG_COLOR_STYLED);
49imageline($im, 600, 200, 600, 700, IMG_COLOR_STYLED);
50imageline($im, 600, 700, 100, 200, IMG_COLOR_STYLED);
51
52setStyleAndThickness($im, $black, 4);
53imageline($im, 150, 150, 650, 150, IMG_COLOR_STYLED);
54imageline($im, 650, 150, 650, 650, IMG_COLOR_STYLED);
55imageline($im, 650, 650, 150, 150, IMG_COLOR_STYLED);
56
57setStyleAndThickness($im, $black, 6);
58imageline($im, 200, 100, 700, 100, IMG_COLOR_STYLED);
59imageline($im, 700, 100, 700, 600, IMG_COLOR_STYLED);
60imageline($im, 700, 600, 200, 100, IMG_COLOR_STYLED);
61
62$ex = imagecreatefrompng(__DIR__ . '/bug43475.png');
63var_dump(calc_image_dissimilarity($ex, $im) < 1e-5);
64?>
65--EXPECT--
66bool(true)
67