|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-06 13:55 UTC] evan at digitalflophouse dot com
Description:
------------
It would be very useful to have some kind of direct access to colors at a given pixel coordinate, or (even better) to have some kind of pixel iterator access.
Imagick currently does this with the Imagick::getImagePixelColor method or the ImagickPixelIterator class.
Reproduce code:
---------------
<?php
/*
an example of how it could work (similar to
Imagick's implementation)
*/
$image = new Gmagick();
$image->readimage("rose.jpg");
$iterator = $image->getpixeliterator();
foreach($iterator as $row) {
foreach ($row as $pixel) {
var_dump($pixel->getcolor());
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
PixelIterator is not included to be consistent with the interface of the GraphicsMagick Wand C library. There are many ways of getting to pixels. For example, one way of getting a 2D matrix of available pixels is as follows: $gmagick = new Gmagick_Fuzzy("magick:rose"); $gmagick->getFuzzyColorGrid(1); class Gmagick_Fuzzy extends Gmagick { /** * Returns the fuzzy color grid of the instantiated image given a size of * grid in pixels * * @param int $gridSize * * @return array */ public function getFuzzyColorGrid($gridSize) { $colorGrid = array(); for ($i = 0; $i < $this->getImageWidth(); $i += $gridSize) { for ($j = 0; $j < $this->getImageHeight(); $j += $gridSize) { $cropped = clone $this; $histogram = $cropped->cropImage($gridSize, $gridSize, $i, $j) ->quantizeImage(1, Gmagick::COLORSPACE_RGB, 0, false, false) ->getImageHistogram(); $colorGrid[$i][$j] = $histogram[0]->getColor(); } } return $colorGrid; } }