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