⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
proc
/
self
/
root
/
usr
/
local
/
src
/
imagick
/
tests
/
View File Name :
081_Imagick_getImageHistogram_basic.phpt
--TEST-- Test Imagick, getImageHistogram --SKIPIF-- <?php require_once(dirname(__FILE__) . '/skipif.inc'); checkFormatPresent('png'); ?> --FILE-- <?php function getColorStatistics($histogramElements, $colorChannel) { $colorStatistics = array(); foreach ($histogramElements as $histogramElement) { //So broken. Wow. Much surprise. Sad. Bad. Sad, bad, sad. //$color = $histogramElement->getColorValueQuantum($colorChannel); $color = $histogramElement->getColorValue($colorChannel); $color = intval($color * 255); $count = $histogramElement->getColorCount(); if (array_key_exists($color, $colorStatistics)) { $colorStatistics[$color] += $count; } else { $colorStatistics[$color] = $count; } } ksort($colorStatistics); return $colorStatistics; } function getImageHistogram() { $backgroundColor = 'black'; $draw = new \ImagickDraw(); $draw->setStrokeWidth(0); //Lines have a wi $imagick = new \Imagick(); $imagick->newImage(500, 500, $backgroundColor); $imagick->setImageFormat("png"); $imagick->drawImage($draw); $histogramWidth = 256; $histogramHeight = 100; // the height for each RGB segment $imagick = new \Imagick(); $imagick->newPseudoImage(640, 480, "magick:logo"); //Resize the image to be small, otherwise PHP tends to run out of memory //This might lead to bad results for images that are pathologically 'pixelly' $imagick->adaptiveResizeImage(200, 200, true); $histogramElements = $imagick->getImageHistogram(); $histogram = new \Imagick(); $histogram->newpseudoimage($histogramWidth, $histogramHeight * 3, 'xc:black'); $histogram->setImageFormat('png'); $getMax = function ($carry, $item) { if ($item > $carry) { return $item; } return $carry; }; $colorValues = array( 'red' => getColorStatistics($histogramElements, \Imagick::COLOR_RED), 'lime' => getColorStatistics($histogramElements, \Imagick::COLOR_GREEN), 'blue' => getColorStatistics($histogramElements, \Imagick::COLOR_BLUE), ); $max = array_reduce($colorValues['red'] , $getMax, 0); $max = array_reduce($colorValues['lime'] , $getMax, $max); $max = array_reduce($colorValues['blue'] , $getMax, $max); $scale = $histogramHeight / $max; $count = 0; foreach ($colorValues as $color => $values) { $draw->setstrokecolor($color); $offset = ($count + 1) * $histogramHeight; foreach ($values as $index => $value) { $draw->line($index, $offset, $index, $offset - ($value * $scale)); } $count++; } $histogram->drawImage($draw); $bytes = $histogram->getImageBlob(); if (strlen($bytes) <= 0) { echo "Failed to generate image.";} } getImageHistogram(); echo "Ok"; ?> --EXPECTF-- Ok