1--TEST-- 2Test Imagick, affineTransformImage 3--SKIPIF-- 4<?php 5$imageMagickRequiredVersion=0x675; 6require_once(dirname(__FILE__) . '/skipif.inc'); 7?> 8--XFAIL-- 9I don't understand what values are returned in which elements of getImageChannelStatistics 10--FILE-- 11<?php 12 13 14function checkAllStatsAreValue($channelStatistics, $value) { 15 16 if ($channelStatistics[Imagick::CHANNEL_RED]['mean'] != $value) { 17 echo "Channel red is wrong " . $channelStatistics[Imagick::CHANNEL_RED]['mean'] . " vs " . $value. "\n"; 18 } 19 if ($channelStatistics[Imagick::CHANNEL_GREEN]['mean'] != $value) { 20 echo "Channel green is wrong " . $channelStatistics[Imagick::CHANNEL_GREEN]['mean'] . " vs " . $value. "\n"; 21 } 22 if ($channelStatistics[Imagick::CHANNEL_BLUE]['mean'] != $value) { 23 echo "Channel blue is wrong " . $channelStatistics[Imagick::CHANNEL_BLUE]['mean'] . " vs " . $value. "\n"; 24 } 25 26 echo "Stats checked\n"; 27} 28 29function affineTransformImage() { 30 $imagick = new \Imagick(); 31 $imagick->newPseudoImage(640, 640, "xc:black"); 32 $draw = new \ImagickDraw(); 33 34 $angle = deg2rad(45); 35 //$angle = deg2rad(3); 36 37 $draw->setFillColor('white'); 38 $draw->setStrokeColor('white'); 39 $draw->setStrokeWidth(10.0); 40 $draw->setStrokeLineCap(Imagick::LINECAP_SQUARE); 41 $draw->setStrokeLineJoin(Imagick::LINEJOIN_BEVEL); 42 43 $draw->line( 44 $start_x = -50, 45 $start_y = -50, 46 $end_x = 690, 47 $end_y = 690 48 ); 49 50 $imagick->drawImage($draw); 51 52 $draw = new \ImagickDraw(); 53 54 $affineRotate = array( 55 "sx" => cos($angle), "sy" => cos($angle), 56 "rx" => sin($angle), "ry" => -sin($angle), 57 "tx" => 0, "ty" => 0, 58 ); 59 60 $draw->affine($affineRotate); 61 62 $imagick->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_BLACK); 63 $imagick->affineTransformImage($draw); 64 $imagick->setImagePage($imagick->getimageWidth(), $imagick->getimageheight(), 0, 0); 65 66 $imagick->cropImage( 67 $imagick->getImageWidth() - 40, 68 $imagick->getImageHeight() - 40, 69 20, 70 20 71 ); 72 73 $imagick->setImageFormat('png'); 74 $imagick->writeImage(__DIR__ . '/test_031.png'); 75 76 77 $lineCheckBlack = clone $imagick; 78 $blackout = new \ImagickDraw(); 79 $blackout->setStrokeColor('black'); 80 $blackout->setFillColor('black'); 81 $blackout->rectangle( 82 ($lineCheckBlack->getImageWidth() / 2) - 20, 83 0, 84 ($lineCheckBlack->getImageWidth() / 2) + 20, 85 $lineCheckBlack->getImageHeight() 86 ); 87 88 $lineCheckBlack->drawImage($blackout); 89 // $lineCheckBlack->writeImage(__DIR__ . '/test_031_blank.png'); 90 91 $whiteout = new \ImagickDraw(); 92 $lineCheckWhite = clone $imagick; 93 $whiteout->setStrokeColor('white'); 94 $whiteout->setFillColor('white'); 95 $whiteout->rectangle( 96 ($lineCheckBlack->getImageWidth() / 2) - 4, 97 0, 98 0, 99 $lineCheckBlack->getImageHeight() 100 ); 101 $whiteout->rectangle( 102 ($lineCheckWhite->getImageWidth() / 2) + 4, 103 0, 104 $lineCheckWhite->getImageWidth(), 105 $lineCheckWhite->getImageHeight() 106 ); 107 108 $lineCheckWhite->drawImage($whiteout); 109 // $lineCheckWhite->writeImage(__DIR__ . '/test_031_white.png'); 110 111 $channelStatistics = $lineCheckWhite->getImageChannelStatistics(); 112 113 echo "Checking white\n"; 114 checkAllStatsAreValue($channelStatistics, Imagick::getQuantum()); 115 116 117 $channelStatistics = $lineCheckBlack->getImageChannelStatistics(); 118// var_dump( 119// "lineCheckBlack channel stats are:", 120// $channelStatistics 121// ); 122 123 echo "Checking black\n"; 124 checkAllStatsAreValue($channelStatistics, 0); 125 126 $bytes = $imagick->getImageBlob(); 127 if (strlen($bytes) <= 0) { echo "Failed to generate image.";} 128} 129 130affineTransformImage() ; 131echo "Ok"; 132?> 133--EXPECTF-- 134Checking white 135Stats checked 136Checking black 137Stats checked 138Ok