1--TEST--
2Test Tutorial, fxAnalyzeImage
3--SKIPIF--
4<?php
5$imageMagickRequiredVersion=0x675;
6require_once(dirname(__FILE__) . '/skipif.inc');
7?>
8--FILE--
9<?php
10
11ini_set('memory_limit','512M');
12
13// Analyzes a one pixel wide image to make it easy to see what the
14// gradient is doing
15function fxAnalyzeImage(\Imagick $imagick) {
16
17    $graphWidth = $imagick->getImageWidth();
18    $sampleHeight = 20;
19    $graphHeight = 128;
20    $border = 2;
21
22    $imageIterator = new \ImagickPixelIterator($imagick);
23
24    $reds = array();
25
26    foreach ($imageIterator as $pixels) { /* Loop trough pixel rows */
27        foreach ($pixels as $pixel) { /* Loop through the pixels in the row (columns) */
28            /** @var $pixel \ImagickPixel */
29            $color = $pixel->getColor();
30            $reds[] = $color['r'];
31        }
32        $imageIterator->syncIterator(); /* Sync the iterator, this is important to do on each iteration */
33    }
34
35    $draw = new \ImagickDraw();
36
37    $strokeColor = new \ImagickPixel('red');
38    $fillColor = new \ImagickPixel('none');
39    $draw->setStrokeColor($strokeColor);
40    $draw->setFillColor($fillColor);
41    $draw->setStrokeWidth(1);
42    $draw->setFontSize(72);
43    $draw->setStrokeAntiAlias(true);
44
45    $x = 0;
46    $points = array();
47
48    foreach ($reds as $red) {
49        $pos = $graphHeight - ($red * $graphHeight / 256);
50        $points[] = array('x' => $x, 'y' => $pos);
51        $x += 1;
52    }
53
54    $draw->polyline($points);
55
56    $plot = new \Imagick();
57    $plot->newImage($graphWidth, $graphHeight, 'white');
58    $plot->drawImage($draw);
59
60    $outputImage = new \Imagick();
61    $outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
62    $outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
63
64    $imagick->resizeimage($imagick->getImageWidth(), $sampleHeight, \Imagick::FILTER_LANCZOS, 1);
65
66    $outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
67    $outputImage->borderimage('black', $border, $border);
68
69    $outputImage->setImageFormat("png");
70    $bytes = $outputImage;
71    if (strlen($bytes) <= 0) { echo "Failed to generate image.";}
72}
73
74
75$arguments = array(5, 1, 0.5);
76
77$imagick = new \Imagick();
78$imagick->newPseudoImage(200, 200, 'gradient:black-white');
79$imagick->functionImage(\Imagick::FUNCTION_POLYNOMIAL, $arguments);
80$imagick->setimageformat('png');
81
82fxAnalyzeImage($imagick);
83
84echo "Ok";
85?>
86--EXPECTF--
87Ok