Return Values

User Contributed Notes 1 note

I've had difficulty getting this function to return the number of unique colors. Also, I wanted to be able to have an array with each $key value being the RGB of the pixel, and each $value value being the number of times that pixel occurs. Basically, a frequency list. For example, you would have "1 / 0 / 0" for red as a $key value, and "25" for the number of times that pixel color was in the image. So, I wrote some code to do that, using a combination of readImageFile, getImageWidth, getImageHeight, getImagePixelColor, and a simple x/y parser, like so :

<?php

// Test File // ---------------------------------------------

// Note: This file was just a picture of a 5x5 red square // inside of a gigantic 521x512 black square, and // then I did a bunch of random, yellow zigzags.