tags:

views:

51

answers:

2

In javascript there is function getImageData(), is there any function in PHP similar to that.

+3  A: 

Have a look at the GD library functions:

http://www.php.net/manual/en/ref.image.php

EDIT:

Specifically, the getimagesize function for dimensions and more :)

EDIT

Hello again. This should help. You can get the RGB values of your image like so:

// the file
$file = 'test.gif';

// get the width and height of the image
list($width, $height) = getimagesize($file);

// create your image resource 
$image = imagecreatefromgif($file);

// you could use the image width and height values here to 
// iterate through each pixel using two nested for loops...

// or... set specific values for $x and $y
$x = 0;
$y = 0;

// get the colour index for the current pixel
$colourIndex = imagecolorat($image, $x, $y);

// get an array of human-readable RGB values 
$colourValues = imagecolorsforindex($image, $colourIndex

// display RGB values
print_r($colourValues);
Darragh
I search in that but can't find any function similar to that.
okay. what do you want to do exactly? I see that getImageData() returns a CanvasPixelArray object. are you trying to extract colour values? Have a look at functions like http://www.php.net/manual/en/function.imagecolorat.php
Darragh
yes i want to extract color values. but don't know how to do it. Please help
okay. I've updated my answer.
Darragh
Thank you for the solution
+1  A: 

GD is your best bet:

http://uk2.php.net/manual/en/function.imagecreatefromjpeg.php

You'll need to know the type (png, jpg) before you start.

fredley