Advertisement
Guest User

Neocolours Petpet Pool Idea

a guest
Aug 31st, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. So here's code to get the average rgb values from an image...
  2.  
  3. Where $item is a .png image, $width and $height are ints. And the code ignores pure black (from transparency) and pure white.
  4.  
  5. $temp = imagecreatefrompng($item);
  6.  
  7. for($x = 0; $x < $width; $x++)
  8. {
  9. for($y = 0; $y < $height; $y++)
  10. {
  11. $colours = imagecolorat($temp, $x, $y);
  12. $readable = imagecolorsforindex($temp, $colours);
  13.  
  14. $r = $readable["red"];
  15. $g = $readable["green"];
  16. $b = $readable["blue"];
  17.  
  18. if(!($r == 0 && $g == 0 && $b == 0) && !($r == 255 && $g == 255 && $b == 255))
  19. {
  20. $red[count($red)] = $r;
  21. $green[count($green)] = $g;
  22. $blue[count($blue)] = $b;
  23. }
  24. }
  25. }
  26.  
  27. $totalred = 0;
  28. $totalgreen = 0;
  29. $totalblue = 0;
  30.  
  31. for($i = 0; $i < count($red); $i++)
  32. {
  33. $totalred = $totalred + $red[$i];
  34. $totalgreen = $totalgreen + $green[$i];
  35. $totalblue = $totalblue + $blue[$i];
  36. }
  37.  
  38. $avgred = intval($totalred / count($red));
  39. $avggreen = intval($totalgreen / count($green));
  40. $avgblue = intval($totalblue / count($blue));
  41.  
  42. Code to compare two images color-wise I'd imagine would be something like this (to my sleep-addled brain, mind you):
  43.  
  44. $r = $avgred;
  45. $g = $avggreen;
  46. $b = $avgblue;
  47.  
  48. 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
  49.  
  50. and you do the same to the petpet files
  51.  
  52. 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
  53.  
  54. 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