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 usaflag watermark. don't forget it's a 16x13 flag gif
        
$usaflag imagecreatefrompng('flag.png');
        
$image2 imagecreatetruecolor($img_w$img_h);
        
imagecopyresampled($image2$usaflag0000$img_w$img_h1613);
        
        
//load the star png
        
$starclone imagecreatefrompng('star.png');
        
$str_w imagesx($starclone);
        
$str_h imagesy($starclone);
        
// the blue is 5x7, 50 stars 6 & 5 stars wide
        // clonestar is 200x157, my B+ geography butt about had an aneurysm
        
$even true;
        
$row 0;
        
$int 0;
        
$dst_w round(((8/16) * $img_w)/6.5);
        
$dst_h round(((7/13) * $img_h)/9.5);
        
        
$buff_x = ($dst_w/2)/2;
        
$buff_y = ($dst_h/2)/2;
        
        
$clone imagecreatetruecolor($dst_w$dst_h);
        
imagealphablending($clonefalse);
        
imagesavealpha($clonetrue);
        
imagecopyresampled($clone$starclone0000$dst_w$dst_h200157);
        for(
$i=0;$i<50;$i++){
            
$int++;
            
$indent $even : ($dst_w/2);
            
$left $dst_w * ($int-1) + $indent $buff_x;
            
$top $dst_h $row $buff_y;
            
imagecopyresampled($image2$clone$left$top00$dst_w$dst_h$dst_w$dst_h);
            if(
$int===&& $even){
                
$even false;
                
$row++;
                
$int=0;
            }elseif(
$int===&& !$even){
                
$even true;
                
$row++;
                
$int=0;
            }
        }
        
        
imagecopymerge($image$image20000$img_w$img_h40);
        
        
imagefilter($imageIMG_FILTER_CONTRAST220);
        
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($usaflag);
        
imagedestroy($starclone);
        
imagedestroy($clone);
        die(
$_FILES['file']['name']);
        exit;
    }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>☆Patriot Image Generator☆</title>
    <link rel="icon" href="favicon.ico" type="image/x-icon" />
    <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 usaflag 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>
</head>

<body>
    <h1>☆Patriot Image Generator☆</h1>
    <script>
        var font = [
            "#ff0000", //☆
            "#f91010", //P
            "#f41f1f", //a
            "#ee2f2f", //t
            "#e83e3e", //r
            "#e24e4e", //i
            "#dd5d5d", //o
            "#d76d6d", //t
            "#d17c7c", //
            "#cb8c8c", //I
            "#c69b9b", //m
            "#c0abab", //a
            "#bababa", //g
            "#ababc0", //e
            "#9b9bc6", //
            "#8c8ccb", //G
            "#7c7cd1", //e
            "#6d6dd7", //n
            "#5d5ddd", //e
            "#4e4ee2", //r
            "#3e3ee8", //a
            "#2f2fee", //t
            "#1f1ff4", //o
            "#1010f9", //r
            "#0000ff"  //☆
        ];
        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>