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