Advertisement
Guest User

Untitled

a guest
Jan 17th, 2012
2,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. //$img = imagecreatefromjpeg();
  4.  
  5. $imgw = imagesx($img);
  6. $imgh = imagesy($img);
  7. $ratio = $imgw/$imgh;
  8. $newh = floor(sqrt(800 / $ratio));
  9. $neww = floor($ratio * $newh);
  10.  
  11. $newimg = imagecreatetruecolor($neww, $newh);
  12. imagecopyresampled($newimg, $img, 0, 0, 0, 0, $neww, $newh, $imgw, $imgh);
  13. imagedestroy($img);
  14.  
  15. $prev_color = false;
  16. $openned_tag = false;
  17.  
  18. $max = 0;
  19. $colors = array();
  20.  
  21. for($j = 0; $j < $newh; $j++) {
  22.   for ($i = 0; $i < $neww; $i++) {
  23.     $color = imagecolorat($newimg, $i, $j);
  24.     $colors[$color] += 1;
  25.     if($max < $colors[$color]) {
  26.         $max = $colors[$color];
  27.         $max_color = $color;
  28.     }
  29.   }
  30. }
  31.  
  32. $out = '<font size="1"><font color="#'.strtoupper(dechex($max_color)).'"><u>';
  33. for($j = 0; $j < $newh; $j++) {
  34.   for ($i = 0; $i < $neww; $i++) {
  35.     $color = imagecolorat($newimg, $i, $j);
  36.     if($prev_color !== $color) {
  37.         $prev_color = $color;
  38.         if($openned_tag) {
  39.             $out .= '</font>';
  40.             $openned_tag = false;
  41.         }
  42.         if ($color != $max_color) {
  43.             $color = strtoupper(dechex($color));
  44.             $out .= '<font color="#'.$color.'">';
  45.             $openned_tag = true;
  46.         }
  47.     }
  48.     $out .= '███';
  49.   }
  50.   $out .= "\n";
  51. }
  52. if($openned_tag) {
  53.     $out .= '</font>';
  54.     $openned_tag = false;
  55. }
  56. $out .= '</u></font></font>';
  57. echo $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement