1--TEST--
2Test for round issues
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . '/skipif.inc');
6if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
7?>
8--FILE--
9<?php
10
11//Test the the calculated values are actually correct.
12$desired_height = 250;
13$imageWidth = 1128;
14
15//Test the the calculated values are actually correct.
16$desired_height = 250;
17$imageWidth = 1128;
18$imageHeight = 1128;
19
20$legacySettings = array(0, 1);
21
22foreach($legacySettings as $legacy) {
23	for ($desired_width = 245; $desired_width < 255; $desired_width++) {
24		$imagick = new Imagick();
25		$imagick->newPseudoImage($imageWidth, $imageHeight, 'xc:white');
26
27		$imagick->cropThumbnailImage(
28			$desired_width, $desired_height,
29			$legacy
30		);
31		$error = false;
32
33		$thumbnailImageWidth = $imagick->getImageWidth();
34		$thumbnailImageHeight = $imagick->getImageHeight();
35
36		if ($thumbnailImageHeight != $desired_height) {
37			echo "Incorrect height for desired_width $desired_width imageHeight $imageHeight".PHP_EOL;
38			$error = true;
39		}
40
41		$expectedWidth = $desired_width;
42		$expectedHeight = $desired_height;
43
44		if ($legacy == true &&
45			$desired_width == 250 &&
46			$desired_height == 250) {
47			// Thumbnail size of 249 x 250 does not matched desired size 250 x 250 for source image of 1128 x 1128
48			$expectedWidth = 249;
49		}
50
51		if ($thumbnailImageWidth != $expectedWidth) {
52			echo "Incorrect width for desired_width $desired_width imageHeight $imageHeight".PHP_EOL;
53			$error = true;
54		}
55
56		if ($thumbnailImageHeight != $expectedHeight) {
57			echo "Incorrect width for desired_width $desired_width imageHeight $imageHeight".PHP_EOL;
58			$error = true;
59		}
60
61		if ($error) {
62			printf(
63				"Thumbnail size of %d x %d does not matched expected size %d x %d for source image of %d x %d. Legacy is %d\n",
64				$thumbnailImageWidth, $thumbnailImageHeight,
65				$desired_width, $desired_height,
66				$imageWidth, $imageHeight,
67				$legacy
68			);
69		}
70	}
71}
72
73
74echo "Done" . PHP_EOL;
75
76?>
77--EXPECTF--
78Done