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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Mon Aug 26 09:01:26 2019 UTC