Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getext($filename) {
- $pos = strrpos($filename,'.');
- $str = substr($filename, $pos);
- return $str;
- }
- $image = $_POST["image"];
- $size = exif_imagetype($image);
- $scalew = 1 / $_POST["scaleW"];
- $scaleh = 1 / $_POST["scaleH"];
- $ext = getext($image);
- if($size == IMAGETYPE_JPEG){
- $img = ImageCreateFromJPEG($image);
- } else if($size == IMAGETYPE_PNG){
- $img = ImageCreateFromPNG($image);
- } else if($size == IMAGETYPE_GIF){
- $img = ImageCreateFromGIF($image);
- } else if($size == IMAGETYPE_BMP){
- $img = ImageCreateFromBMP($image);
- } else {
- echo'Wrong File Type';
- }
- $width = imagesx($img);
- $height = imagesy($img);
- for($h=0;$h<$height;$h=$h+$scaleh){
- if($h > 0){
- echo '
- ';
- }
- for($w=0;$w<=$width;$w=$w+$scalew){
- $rgb = ImageColorAt($img, floor($w), floor($h));
- $r = ($rgb >> 16) & 0xFF;
- $g = ($rgb >> 8) & 0xFF;
- $b = $rgb & 0xFF;
- $bright = ($r + $g + $b) / 3;
- if($w >= $width){
- } else {
- if($r > $g + 50 and $r > $b + 50){
- //Red
- if($bright >= 54){
- echo "e";
- } else {
- echo "c";
- }
- } else if($g > $r + 50 and $g > $b + 50){
- //Green
- if($bright >= 54){
- echo "5";
- } else {
- echo "d";
- }
- } else if($b > $r + 50 and $b > $g + 50){
- //Blue
- if($bright >= 92){
- echo "a";
- } else {
- echo "b";
- }
- } else if($r > $b + 10 and $g > $b + 10){
- //Red + Green
- if($bright >= 132){
- echo "4";
- } else {
- echo "1";
- }
- } else if($g > $r + 10 and $b > $r + 10){
- //Green + Blue
- if($bright >= 96){
- echo "3";
- } else {
- echo "9";
- }
- } else if($r > $g + 10 and $b > $g + 10){
- //Red + Blue
- if($bright >= 145){
- echo "6";
- } else {
- echo "2";
- }
- } else {
- if($bright >= 200){
- echo "0";
- } else if($bright >= 130){
- echo "8";
- } else if($bright >= 55){
- echo "7";
- } else {
- echo "f";
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment