php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #58880 Implement some kind of direct pixel access?
Submitted: 2009-10-06 13:55 UTC Modified: 2010-06-19 04:24 UTC
From: evan at digitalflophouse dot com Assigned: vitoc (profile)
Status: Closed Package: gmagick (PECL)
PHP Version: 5.2.6 OS: Ubuntu 9.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: evan at digitalflophouse dot com
New email:
PHP Version: OS:

 

 [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());
    }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-19 04:24 UTC] vito@php.net
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;
    }
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 16:01:31 2024 UTC