Left4Cake2

httpimg (php)

Apr 24th, 2013
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.06 KB | None | 0 0
  1. <?php
  2. function getext($filename) {
  3.     $pos = strrpos($filename,'.');
  4.     $str = substr($filename, $pos);
  5.     return $str;
  6. }
  7. $image = $_POST["image"];
  8. $size = exif_imagetype($image);
  9. $scalew = 1 / $_POST["scaleW"];
  10. $scaleh = 1 / $_POST["scaleH"];
  11. $ext = getext($image);
  12. if($size == IMAGETYPE_JPEG){
  13.     $img = ImageCreateFromJPEG($image);
  14. } else if($size == IMAGETYPE_PNG){
  15.     $img = ImageCreateFromPNG($image);
  16. } else if($size == IMAGETYPE_GIF){
  17.     $img = ImageCreateFromGIF($image);
  18. } else if($size == IMAGETYPE_BMP){
  19.     $img = ImageCreateFromBMP($image);
  20. } else {
  21.     echo'Wrong File Type';
  22. }
  23. $width = imagesx($img);
  24. $height = imagesy($img);
  25.  
  26. for($h=0;$h<$height;$h=$h+$scaleh){
  27.     if($h > 0){
  28.                 echo '
  29. ';
  30.     }
  31.     for($w=0;$w<=$width;$w=$w+$scalew){
  32.         $rgb = ImageColorAt($img, floor($w), floor($h));
  33.         $r = ($rgb >> 16) & 0xFF;
  34.         $g = ($rgb >> 8) & 0xFF;
  35.         $b = $rgb & 0xFF;
  36.         $bright = ($r + $g + $b) / 3;
  37.         if($w >= $width){
  38.         } else {
  39.             if($r > $g + 50 and $r > $b + 50){
  40.             //Red
  41.                 if($bright >= 54){
  42.                     echo "e";
  43.                 } else {
  44.                     echo "c";
  45.                 }
  46.            } else if($g > $r + 50 and $g > $b + 50){
  47.            //Green
  48.                 if($bright >= 54){
  49.                     echo "5";
  50.                 } else {
  51.                     echo "d";
  52.                 }
  53.             } else if($b > $r + 50 and $b > $g + 50){
  54.             //Blue
  55.                 if($bright >= 92){
  56.                     echo "a";
  57.                 } else {
  58.                     echo "b";
  59.                 }
  60.            } else if($r > $b + 10 and $g > $b + 10){
  61.             //Red + Green
  62.                 if($bright >= 132){
  63.                     echo "4";
  64.                 } else {
  65.                     echo "1";
  66.                 }
  67.             } else if($g > $r + 10 and $b > $r + 10){
  68.             //Green + Blue
  69.                 if($bright >= 96){
  70.                     echo "3";
  71.                 } else {
  72.                     echo "9";
  73.                 }
  74.             } else if($r > $g + 10 and $b > $g + 10){
  75.             //Red + Blue
  76.                 if($bright >= 145){
  77.                     echo "6";
  78.                 } else {
  79.                     echo "2";
  80.                 }
  81.            } else {
  82.                 if($bright >= 200){
  83.                     echo "0";
  84.                 } else if($bright >= 130){
  85.                     echo "8";
  86.                 } else if($bright >= 55){
  87.                     echo "7";
  88.                 } else {
  89.                     echo "f";
  90.                 }
  91.            }
  92.  
  93.         }
  94.     }
  95. }
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment