RewriteEngine On
RewriteRule ^pride.png$ index.php [NC,L,QSA]
<?php
session_start
();
if(isset(
$_GET['source'])){
    echo 
'<span style="padding:10px;margin:10px;border:1px solid #000;display:block;" title=".htaccess">';
    
highlight_file(".htaccess");
    echo 
'</span><span style="padding:10px;margin:10px;border:1px solid #000;display:block;" title="index.php">';
    
highlight_file("index.php");
    echo 
'</span>';
    exit;
}elseif(isset(
$_FILES) && is_array($_FILES) && isset($_FILES['file'])){
    if(
getimagesize($_FILES['file']['tmp_name'])!==false){
        
header("Content-Type: text/plain");
        
        function 
open_image($file) {
            
$size=getimagesize($file);
            switch(
$size["mime"]){
                case 
"image/jpeg":
                    
$im imagecreatefromjpeg($file); //jpeg file
                
break;
                case 
"image/gif":
                    
$im imagecreatefromgif($file); //gif file
              
break;
              case 
"image/png":
                  
$im imagecreatefrompng($file); //png file
              
break;
            default:
                
$im=false;
            break;
            }
            return 
$im;
        }  
        
$uploaded open_image($_FILES['file']['tmp_name']);
        
        
$img_w imagesx($uploaded);
        
$img_h imagesy($uploaded);
        
$image imagecreatetruecolor($img_w$img_h);
        
$white imagecolorallocate($image255255255);
        
imagefill($image00$white);
        
imagecopyresampled($image$uploaded0000$img_w$img_h$img_w$img_h);   

        
//Load the rainbow watermark. don't forget it's a 1x6 rainbow jpeg
        
$rainbow imagecreatefromjpeg('rainbow.jpg');
        
$image2 imagecreatetruecolor($img_w$img_h);
        
imagecopyresampled($image2$rainbow0000$img_w$img_h16);   
        
        
imagecopymerge($image$image20000$img_w$img_h60);
        
        
imagefilter($imageIMG_FILTER_CONTRAST200);
        
        
ob_start(); 
            
imagejpeg($image);
            
$image_data ob_get_contents();
        
ob_end_clean();
        
        
$_SESSION[$_FILES['file']['name']] = base64_encode($image_data);
        
        
imagedestroy($image);
        
imagedestroy($image2);
        
imagedestroy($uploaded);
        
imagedestroy($rainbow);
        
        die(
$_FILES['file']['name']);
    }else{
        die(
"error");
    }
}elseif(isset(
$_GET['btoa'])){
    
header("Content-Type: image/jpeg");
    die(
base64_decode($_SESSION[$_GET['btoa']]));
}
?><!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Pride Image Generator</title>
    <script src="//jakeis.com/lib/jquery-2.1.3.min.js"></script>
    <script src="//jakeis.com/lib/dropzone.js"></script>
    <script>
        Dropzone.options.prideGen = {
          paramName: "file", // The name that will be used to transfer the file
          maxFilesize: 2, // MB
          maxFiles: 1,
          acceptedFiles: "image/*",
          dictDefaultMessage: "<p>Drop an image here or click here to rainbow an image.</p><p>Accepts JPEG and PNG. (2mb max)</p>",
          addedfile: function(file, done) {
              jQuery("h2").text("uploading...");
              var upload = new FormData();
              upload.append("file",file);
            jQuery.ajax({
                url: "index.php",
                data: upload,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                success: function(tmp){
                    if(tmp==="error"){
                        alert("There seems to be trouble with this image.");
                        return false;
                    }
                    //alert(tmp);
                    jQuery("#images").append(
                        jQuery('<img>').attr({
                            src: "pride.png?btoa=" + escape(tmp)
                        })
                    );
                },
                error: function(){
                    alert("There seems to be trouble with this image.");
                },
                complete: function(){
                    jQuery("h2").text("");
                }
            });
          }
        };
    </script>
    <style type="text/css">
        body{
            padding:40px;
        }
        #images, body{
            text-align:center;
        }
        form{
            padding: 60px;
            border: 2px #999 solid;
            min-width:50%;
            display:inline-block;
        }
        img{
            max-width:70%;
            margin:25px;
        }
    </style>
    <link rel="icon" href="favicon.ico" type="image/x-icon" />
</head>

<body>
    <h1>Pride Image Generator</h1>
    <script>
        var font = [
            "#FF0000", //P
            "#FF4900", //r
            "#FF9200", //i
            "#FFDB00", //d
            "#FFDB00", //e
            "#B6ff00",
            "#B6ff00", //I 
            "#6Dff00", //m
            "#24ff00", //a
            "#00ff00", //g
            "#00ff49", //e
            "#00ff92", 
            "#00ffDB", //g
            "#00ffff", //e
            "#00DBff", //n
            "#0092ff", //e
            "#0049ff", //r 
            "#0000ff", //a
            "#2400ff", //t
            "#6D00ff", //o
            "#B600ff"  //r
        ];
        jQuery('h1').html(
            jQuery('h1').text().split('').map((function(letter,i){
                return jQuery('<font>').attr('color',font[i]).text(letter)[0].outerHTML;
            })).join('')
        );
    </script>
    <h2></h2>
    <form action="index.php" class="dropzone" id="prideGen">
      <div class="fallback">
        <input name="file" type="file" multiple />
      </div>
    </form>
    <div id="images"></div>
</body>
</html>