xref: /PHP-8.2/ext/gd/tests/bug43475.phpt (revision a375d547)
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?>
11--FILE--
12<?php
13require_once __DIR__ . '/similarity.inc';
14
15function setStyleAndThickness($im, $color, $thickness)
16{
17    $style = array();
18    $i = 0;
19    while ($i < 16 * $thickness) {
20        $style[$i++] = $color;
21    }
22    while ($i < 20 * $thickness) {
23        $style[$i++] = IMG_COLOR_TRANSPARENT;
24    }
25    while ($i < 28 * $thickness) {
26        $style[$i++] = $color;
27    }
28    while ($i < 32 * $thickness) {
29        $style[$i++] = IMG_COLOR_TRANSPARENT;
30    }
31    imagesetstyle($im, $style);
32    imagesetthickness($im, $thickness);
33}
34
35$im = imagecreate(800, 800);
36imagecolorallocate($im, 255, 255, 255);
37$black = imagecolorallocate($im, 0, 0, 0);
38
39setStyleAndThickness($im, $black, 1);
40imageline($im,  50, 250, 550, 250, IMG_COLOR_STYLED);
41imageline($im, 550, 250, 550, 750, IMG_COLOR_STYLED);
42imageline($im, 550, 750,  50, 250, IMG_COLOR_STYLED);
43
44setStyleAndThickness($im, $black, 2);
45imageline($im, 100, 200, 600, 200, IMG_COLOR_STYLED);
46imageline($im, 600, 200, 600, 700, IMG_COLOR_STYLED);
47imageline($im, 600, 700, 100, 200, IMG_COLOR_STYLED);
48
49setStyleAndThickness($im, $black, 4);
50imageline($im, 150, 150, 650, 150, IMG_COLOR_STYLED);
51imageline($im, 650, 150, 650, 650, IMG_COLOR_STYLED);
52imageline($im, 650, 650, 150, 150, IMG_COLOR_STYLED);
53
54setStyleAndThickness($im, $black, 6);
55imageline($im, 200, 100, 700, 100, IMG_COLOR_STYLED);
56imageline($im, 700, 100, 700, 600, IMG_COLOR_STYLED);
57imageline($im, 700, 600, 200, 100, IMG_COLOR_STYLED);
58
59$ex = imagecreatefrompng(__DIR__ . '/bug43475.png');
60var_dump(calc_image_dissimilarity($ex, $im) < 1e-5);
61?>
62--EXPECT--
63bool(true)
64