Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- So here's code to get the average rgb values from an image...
- Where $item is a .png image, $width and $height are ints. And the code ignores pure black (from transparency) and pure white.
- $temp = imagecreatefrompng($item);
- for($x = 0; $x < $width; $x++)
- {
- for($y = 0; $y < $height; $y++)
- {
- $colours = imagecolorat($temp, $x, $y);
- $readable = imagecolorsforindex($temp, $colours);
- $r = $readable["red"];
- $g = $readable["green"];
- $b = $readable["blue"];
- if(!($r == 0 && $g == 0 && $b == 0) && !($r == 255 && $g == 255 && $b == 255))
- {
- $red[count($red)] = $r;
- $green[count($green)] = $g;
- $blue[count($blue)] = $b;
- }
- }
- }
- $totalred = 0;
- $totalgreen = 0;
- $totalblue = 0;
- for($i = 0; $i < count($red); $i++)
- {
- $totalred = $totalred + $red[$i];
- $totalgreen = $totalgreen + $green[$i];
- $totalblue = $totalblue + $blue[$i];
- }
- $avgred = intval($totalred / count($red));
- $avggreen = intval($totalgreen / count($green));
- $avgblue = intval($totalblue / count($blue));
- Code to compare two images color-wise I'd imagine would be something like this (to my sleep-addled brain, mind you):
- $r = $avgred;
- $g = $avggreen;
- $b = $avgblue;
- where obviously $avgred, etc are taken from some kind of file, since the aggregation should be done all at once and THEN the matching should be done afterwards
- and you do the same to the petpet files
- and then you just run them through, seeing if the petpet avgs come within a threshold (20? 30? no idea, it'd have to be worked out with trial-and-error at first). Not sure if it should be done on an individual rgb value basis or if the values should be added and THEN compared
- I actually have code to take ALL of the images from a directory and aggregate them (no save function yet though), but I remembered that neocolours doesn't host the images, so uhhhhhhh...yeah. It'd probably have to involve mysql calls, but I don't know how the tables are set up, so I can't really write code for that.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement