PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Thu May 28, 2020 2:28 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 16, 2003 8:10 pm 
Forum Newbie

Joined: Fri May 16, 2003 8:10 pm
Posts: 1
When looking at the documentation for these two functions, they seem to work together, but there is a redundancy that I don't understand.

The "imageColorAt()" function takes two parameters as explained in the documentation:

+ int imagecolorat ( resource image, int x, int y)

+ Returns the index of the color of the pixel at the specified location in the image specified by image.

The "imageColorsForIndex()" function also takes two parameters as noted:

+ array imagecolorsforindex ( resource image, int index)

+ This returns an associative array with red, green, and blue keys that contain the appropriate values for the specified color index.

Since you need to use the imageColorsAt() function to obtain the index, and the imageColorsAt() function has already accessed the resource image for this value, why does the imageColorsForIndex() function need to reaccess the resource image?

Shouldn't it just be able to return the RGB values by evaluating the color index?

If anyone can give some insight, it would be greatly appreciated.



 Post subject:
PostPosted: Thu May 22, 2003 9:54 am 
Forum Contributor

Joined: Thu Feb 27, 2003 8:22 am
Posts: 273
Location: UK
It could on a 32bit truecolour jpeg image as the index exactly mimics the hex rrggbb - on images with reduced palettes the index is a numeric that stores the hex values - eg [12]=>EB56DA - so there is no quick way of backtracking from the colour to get the index (unlike on a truecolour palette which always has 16.7 million indices, one for each colour and each index converted to hex would represent the colour [16777216]=>FFFFFF)

Also, referencing the image pointer helps once you start pulling in multiple images for create schemes.

Realistically you could merge the calls to

$var = imagecolorsforindex($img,imagecolorat($img,$pos_x,$pos_y));

On a subnote: you cannot iterate the entire palette array of a truecolour image by using for($x=0; $x<imagecolorstotal($img); $x++) - no timeouts occur, it just won't let you.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 8 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group