1--TEST--
2Test Tutorial, deconstructGif
3--SKIPIF--
4<?php
5$imageMagickRequiredVersion=0x675;
6require_once(dirname(__FILE__) . '/skipif.inc');
7?>
8--FILE--
9<?php
10
11$deconstruct = 1;
12
13function makeSimpleGif($deconstruct) {
14    $aniGif = new \Imagick();
15    $aniGif->setFormat("gif");
16
17    $circleRadius = 20;
18    $imageFrames = 6;
19    $imageSize = 200;
20
21    $background = new \Imagick();
22    $background->newpseudoimage($imageSize, $imageSize, "canvas:gray");
23
24    $blackWhite = new \Imagick();
25    $blackWhite->newpseudoimage($imageSize, $imageSize, "gradient:black-white");
26
27    $backgroundPalette = clone $background;
28    $backgroundPalette->quantizeImage(240, \Imagick::COLORSPACE_RGB, 8, false, false);
29
30    $blackWhitePalette = clone $blackWhite;
31    $blackWhitePalette->quantizeImage(16, \Imagick::COLORSPACE_RGB, 8, false, false);
32
33    $backgroundPalette->addimage($blackWhitePalette);
34
35    for($count=0 ; $count<$imageFrames ; $count++) {
36        echo "Frame: ".$count."\n";
37        $drawing = new \ImagickDraw();
38        $drawing->setFillColor('white');
39        $drawing->setStrokeColor('rgba(64, 64, 64, 0.8)');
40        $strokeWidth = 4;
41        $drawing->setStrokeWidth($strokeWidth);
42
43        $distanceToMove = $imageSize + (($circleRadius + $strokeWidth) * 2);
44        $offset = ($distanceToMove * $count / ($imageFrames -1)) - ($circleRadius + $strokeWidth);
45        $drawing->translate($offset, ($imageSize / 2) + ($imageSize / 3 * cos(20 * $count / $imageFrames)));
46        $drawing->circle(0, 0, $circleRadius, 0);
47
48        $frame = clone $background;
49        $frame->drawimage($drawing);
50        $frame->clutimage($backgroundPalette);
51        $frame->setImageDelay(10);
52        $aniGif->addImage($frame);
53    }
54
55    if ($deconstruct == true) {
56        $aniGif = $aniGif->deconstructImages();
57    }
58
59    $bytes = $aniGif->getImagesBlob();
60    if (strlen($bytes) <= 0) { echo "Failed to generate image.";}
61}
62
63makeSimpleGif($deconstruct) ;
64echo "Ok";
65?>
66--EXPECTF--
67Frame: 0
68Frame: 1
69Frame: 2
70Frame: 3
71Frame: 4
72Frame: 5
73Ok