Basic PHP document management system, including automatic detection of corporate logos in letters
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logo.matrix.inc.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?PHP
  2. function getLogoMatrix($logo) {
  3. $matrix = array();
  4. for ($x = 0; $x < imagesx($logo); $x++) {
  5. for ($y = 0; $y < imagesy($logo); $y++) {
  6. $c = imagecolorat($logo, $x, $y);
  7. $r = 255 * round((($c >> 16) & 0xFF) / 255, 0);
  8. $g = 255 * round((($c >> 8) & 0xFF) / 255, 0);
  9. $b = 255 * round(( $c & 0xFF) / 255, 0);
  10. $xo = floor(10 * $x / imagesx($logo));
  11. $yo = floor( 5 * $y / imagesy($logo));
  12. if (!isset($matrix[$xo][$yo])) {
  13. $matrix[$xo][$yo] = array('r' => 0, 'g' => 0, 'b' => 0, 'c' => 0);
  14. }
  15. $matrix[$xo][$yo]['r'] += $r;
  16. $matrix[$xo][$yo]['g'] += $g;
  17. $matrix[$xo][$yo]['b'] += $b;
  18. $matrix[$xo][$yo]['c']++;
  19. }
  20. }
  21. $res = '';
  22. foreach ($matrix as $x => $row) {
  23. foreach ($row as $y => $data) {
  24. extract($data);
  25. $r /= $c; $g /= $c; $b /= $c;
  26. $r = floor($r); $g = floor($g); $b = floor($b);
  27. $r = round($r / 127); $g = round($g / 127); $b = round($b / 127);
  28. $v = chr(ord('A') + $r + $g * 3 + $b * 6);
  29. $res .= $v;
  30. }
  31. }
  32. return $res;
  33. }
  34. ?>