1--TEST-- 2Test Imagick, Imagick::exportImagePixels 3--SKIPIF-- 4<?php 5$imageMagickRequiredVersion=0x687; 6require_once(dirname(__FILE__) . '/skipif.inc'); 7?> 8--FILE-- 9<?php 10 11$imagick = new \Imagick(); 12$imagick->newPseudoImage(256, 256, "gradient:black-white"); 13 14$pixelTypes = array( 15 Imagick::PIXEL_CHAR => function($v) { return $v / 255; } , 16 Imagick::PIXEL_DOUBLE => function($v) { return $v; } , 17 Imagick::PIXEL_FLOAT => function($v) { return $v; } , 18 Imagick::PIXEL_LONG => function($v) { return $v / 4294967295; }, 19 Imagick::PIXEL_QUANTUM => function($v) { return $v / Imagick::getQuantum(); } , 20 Imagick::PIXEL_SHORT => function($v) { return $v / 65535; } , 21 22 // This is not supported as ints close to 64bits are weird in PHP 23 // Imagick::PIXEL_LONGLONG => function($v) { return $v / (2 << 64 -1 ); } , 24); 25 26$v = Imagick::getVersion(); 27if ($v['versionNumber'] < 0x700) { 28 //This test will probably fail on 32bit platforms. If you see this please 29 //submit a PR that fixes the problem. 30 $pixelTypes[Imagick::PIXEL_INTEGER] = function($v) { return $v / 4294967295; }; 31} 32 33 34 35foreach ($pixelTypes as $pixelType => $scaleFn) { 36 try { 37 $pixels = $imagick->exportImagePixels(0, 0, 1, 256, "R", $pixelType); 38 39 for ($i = 0; $i<10 ; $i++) { 40 $expectedValue = $i / 255; 41 $scaledActualValue = $scaleFn($pixels[$i]); 42 43 if (abs($expectedValue - $scaledActualValue) > 0.0001) { 44 echo "pixel type $pixelType has incorrect values. They should be 0/255, 1/255, 2/255... 255/255 or the scaled equivalent\n"; 45 var_dump($pixels); 46 break; 47 } 48 } 49 } 50 catch (\Exception $e) { 51 echo "Exception caught for pixelType: $pixelType "; 52 echo $e->getMessage(); 53 } 54} 55 56 57echo "Ok"; 58?> 59--EXPECTF-- 60Ok