<?php
// emoji_image.php
// Get helped out by Google PageSpeed to create an emoji image
// November, 2020


// echo "IMG_CROP_WHITE\n";
// $im = imagecreatefrompng("orig.png");
// $im_crop = imagecropauto($im, IMG_CROP_WHITE);
// imagepng($im_crop, "crop_orig.png");
// var_dump(imagesx($im_crop));
// var_dump(imagesy($im_crop));
// @unlink("crop_orig.png");
/*
$image_src = imagecreatefrompng("orig.png");

$croppedImage = imagecropauto($image_src,IMG_CROP_WHITE);

//header( 'Content-Type: image/png');

imagepng($croppedImage);*/

$dstyle="    document.getElementById('dstyle').innerHTML+='<style> #thone { background:URL(\"' + document.getElementById('result').innerHTML + '\"); background-repeat:no-repeat;  }  #thtwo { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL(\"' + document.getElementById('result').innerHTML + '\"); background-repeat:repeat; }    #hthree { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL(\"' + document.getElementById('result').innerHTML + '\"); background-size:cover; background-repeat:no-repeat;  }  #result { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL(\"' + document.getElementById('result').innerHTML + '\"); background-size:contain; background-repeat:no-repeat;  }  #borderimg1 { border-image: url(\"' + document.getElementById('result').innerHTML + '\") 30%; border-image-repeat: round; }  #borderimg2 { border-image: url(\"' + document.getElementById('result').innerHTML + '\") 20%; border-image-repeat: stretch; } </style>';   ";
$transparent="transparent";
$ei="Emoji Image";
$cr="Creator";
$imgw="image";
$iimage="image";
$iaudio="ywnft";
$ivideo="ywnft";
$gps="window.open(\"https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fwww.rjmprogramming.com.au%2FPHP%2Femoji_image.php&tab=mobile\",\"_blank\",\"top=50,left=50,height=900,width=1300\");";

$hblurb="Copy (Image) from Google PageSpeed <br>(thanks, and note to toggle between mobile and desktop tabs perhaps) <br>and Paste via macOS Alt-PrtScr Below (for Data URI as well) <br>or to an Image Editor that can Crop out Extraneous White Parts <br>or Resize Image and Save <br>(ready for Border Image or Background Image or just Image purposes)";

if (isset($_GET['audio'])) {
  $hblurb="Copy Audio <br>via Finder or Windows Explorer <br>and come Back Here to Paste that Data";
  $ei="Audio";
  $cr="Paster";
  $imgw="audio";
  $iaudio="audio";
  $iimage="ywnft";
  $ivideo="ywnft";
  $gps="";
} else if (isset($_GET['video'])) {
  $hblurb="Copy Video <br>via Finder or Windows Explorer <br>and come Back Here to Paste that Data";
  $ei="Video";
  $cr="Paster";
  $imgw="video";
  $ivideo="video";
  $iaudio="ywnft";
  $iimage="ywnft";
  $gps="";
}

function mycrop($src, array $rect) {  // thanks to https://stackoverflow.com/questions/26722811/imagecrop-alternative-for-php-5-5
    $dest = imagecreatetruecolor($rect['width'], $rect['height']);
    imagecopy(
        $dest,
        $src,
        0,
        0,
        $rect['x'],
        $rect['y'],
        $rect['width'],
        $rect['height']
    );

    return $dest;
}


function imageTrimBox($img, $hex=null) {   // thanks to https://stackoverflow.com/questions/1669683/crop-whitespace-from-image-in-php
if (!ctype_xdigit($hex)) $hex = imagecolorat($img, 0,0);
$b_top = $b_lft = 0;
$b_rt = $w1 = $w2 = imagesx($img);
$b_btm = $h1 = $h2 = imagesy($img);

do {
    //top
    for(; $b_top < $h1; ++$b_top) {
        for($x = 0; $x < $w1; ++$x) {
            if(imagecolorat($img, $x, $b_top) != $hex) {
                break 2;
            }
        }
    }

    // stop if all pixels are trimmed
    if ($b_top == $b_btm) {
        $b_top = 0;
        $code = 2;
        break 1;
    }

    // bottom
    for(; $b_btm >= 0; --$b_btm) {
        for($x = 0; $x < $w1; ++$x) {
            if(imagecolorat($img, $x, $b_btm-1) != $hex) {
                break 2;
            }
        }
    }

    // left
    for(; $b_lft < $w1; ++$b_lft) {
        for($y = $b_top; $y <= $b_btm; ++$y) {
            if(imagecolorat($img, $b_lft, $y) != $hex) {
                break 2;
            }
        }
    }

    // right
    for(; $b_rt >= 0; --$b_rt) {
        for($y = $b_top; $y <= $b_btm; ++$y) {
            if(imagecolorat($img, $b_rt-1, $y) != $hex) {
                break 2;
            }
        }

    }

    $w2 = $b_rt - $b_lft;
    $h2 = $b_btm - $b_top;
    $code = ($w2 < $w1 || $h2 < $h1) ? 1 : 0;
} while (0);

// result codes:
// 0 = Trim Zero Pixels
// 1 = Trim Some Pixels
// 2 = Trim All Pixels
return array(
    '#'     => $code,   // result code
    'l'     => $b_lft,  // left
    't'     => $b_top,  // top
    'r'     => $b_rt,   // right
    'b'     => $b_btm,  // bottom
    'w'     => $w2,     // new width
    'h'     => $h2,     // new height
    'w1'    => $w1,     // original width
    'h1'    => $h1,     // original height
);
}

$gei="";
$xgei="";
if (isset($_GET['emoji_textarea_image'])) {
    $gei=str_replace("+"," ",urldecode($_GET['emoji_textarea_image']));
    $xgei=$gei;
}

if (isset($_POST['emoji_uncropped_image']) && isset($_POST['ewidth']) && isset($_POST['eheight'])) {
  // data:image/png;base64,
  $datauri=str_replace(" ","+",urldecode($_POST['emoji_uncropped_image']));
  if (strpos($datauri, "data:image/") !== false && strpos($datauri, ";base64,") !== false) {
    $newdu = $datauri;
    $ext = explode("data:image/", explode(";base64,",$datauri)[0])[1];
    $rnum = "" . rand(0,198675433);
    $im = imagecreatefromstring(base64_decode(explode(";base64,",$datauri)[1]));

    if (1 == 1) {
    // find the trimmed image border
    $box = imageTrimBox($im);

    // copy cropped portion
    $im_crop = imagecreate($box['w'], $box['h']);
    imagecopy($im_crop, $im, 0, 0, $box['l'], $box['t'], $box['w'], $box['h']);

    } else {

    $im_crop = mycrop($im, ['x' => 0, 'y' => 0, 'width' => str_replace("+"," ",urldecode($_POST['ewidth'])), 'height' => str_replace("+"," ",urldecode($_POST['eheight']))]);
    }
    $delit="";
    //$im_crop = imagecropauto($im, IMG_CROP_WHITE);
    if (strtolower($ext) == "png") { // || substr(strtolower($ext),0,2) == "jp" || strtolower($ext) == "gif") {
      imagepng($im_crop, "crop_orig" . $rnum . ".png");
      $newdu = "data:image/png;base64," . base64_encode(file_get_contents("crop_orig" . $rnum . ".png"));
      // $delit="rm -f " . dirname(__FILE__) . "/crop_orig" . $rnum . ".png"; // 
      unlink("crop_orig" . $rnum . ".png");
    } else if (substr(strtolower($ext),0,2) == "jp") {
      imagejpeg($im_crop, "crop_orig" . $rnum . ".jpeg");
      $newdu = "data:image/jpeg;base64," . base64_encode(file_get_contents("crop_orig" . $rnum . ".jpeg"));
      // $delit="rm -f " . dirname(__FILE__) . "/crop_orig" . $rnum . ".jpeg"; // 
      unlink("crop_orig" . $rnum . ".jpeg");
    } else if (strtolower($ext) == "gif") {
      imagegif($im_crop, "crop_orig" . $rnum . ".gif");
      $newdu = "data:image/" . $ext . ";base64," . base64_encode(file_get_contents("crop_orig" . $rnum . ".gif"));
      // $delit="rm -f " . dirname(__FILE__) . "/crop_orig" . $rnum . ".gif"; // 
      unlink("crop_orig" . $rnum . ".gif");
    //} else if (strtolower($ext) == "bmp") {
    //  imagebmp($im_crop, "crop_orig" . $rnum . ".bmp");
    //  $newdu = "data:image/" . $ext . ";base64," . base64_encode(file_get_contents("crop_orig" . $rnum . ".bmp"));
    //  unlink("crop_orig" . $rnum . ".bmp");
    }
    imagedestroy($im);
    imagedestroy($im_crop);
    
    echo "<html><body onload=\" parent.document.getElementById('result').innerHTML='" . $newdu . "'; var imgs=parent.document.getElementsByTagName('img'); if (imgs.length > 0) { imgs[0].src='" . $newdu . "'; } parent.dorn(); \"></body></html>";
    if ($delit != "") { exec("sleep 30; " . $delit); }
  }
} else if (isset($_GET['emoji_rm_image'])) {
  if (file_exists('emoji_image.txt')) {
  $etext=file_get_contents('emoji_image.txt');
  if ($etext != trim($etext) && trim($etext) == str_replace("+"," ",urldecode($_GET['emoji_rm_image']))) {
  unlink('emoji_image.txt');
  }
  }
  //exec("sleep 50; rm -f " . dirname(__FILE__) . "/emoji_image.txt");
  exit;
} else if (isset($_GET['emoji_mr_image'])) {
  exit;
} else if (file_exists('emoji_image.txt')) {
  $etext=file_get_contents('emoji_image.txt');
  if ($etext != trim($etext)) {
  unlink('emoji_image.txt');
  } else {
  file_put_contents('emoji_image.txt', $etext . ' ');
  }
  $etext=trim($etext);
  if (substr(($etext . "z"),0,1) <= "9") {
  echo "<html><head><meta charset='utf-8'></head><body><p style='font-size:256px;'>&#" . str_replace("\n","<br>",str_replace(".", ";&#", str_replace("+"," ",$etext))) . ";</p></body></html>";
  } else {
  echo "<html><head><meta charset='utf-8'></head><body><p style='font-size:256px;'>" . str_replace("\n","<br>",$etext) . "</p></body></html>";
  }
} else if (trim($gei) != "" || isset($_GET['emoji_image'])) {
  if (trim($gei) == "") {
    $gei=str_replace("+"," ",urldecode($_GET['emoji_image']));
  } else if (isset($_GET['emoji_image'])) {
    $pregei=str_replace("+"," ",urldecode($_GET['emoji_image']));
    if (trim($pregei) != "") {
      $pregei.="\n\n" . $gei;
      $gei=$pregei;
    }
  }
  if (!isset($_GET['audio']) && !isset($_GET['video'])) {
  file_put_contents('emoji_image.txt',  str_replace(";","",str_replace("&#","",str_replace(";&#",".",$gei)))  );
  }
  if (strpos($gei, ".") !== false || strpos($gei, "&#") !== false || strpos($gei, ";") !== false) {
    $xgei="&#" . str_replace(";","",str_replace("&#","",str_replace(";&#",".",$gei))) . ";";
  } else {
    $xgei=$gei;
  }
  $one="1";
  $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
  if ($isiPad === false) {
    $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPhone');
  }
  if ($isiPad === false) {
    $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android');
  }
  if ($isiPad) { 
    $one="3"; 
    $transparent="white";
    // $dstyle="    document.getElementById('dstyle').innerHTML+='<style> #thone { background:URL(\"' + document.getElementById('result').innerHTML + '\"); background-repeat:no-repeat;  }  #thtwo { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL(\"' + document.getElementById('result').innerHTML + '\"); background-repeat:repeat; } #borderimg1 { border-image: url(\"' + '" . explode("/",$delit)[-1 + sizeof(explode("/",$delit))] . "' + '\") 30%; border-image-repeat: round; }  #borderimg2 { border-image: url(\"' + '" . explode("/",$delit)[-1 + sizeof(explode("/",$delit))] . "' + '\") 20%; border-image-repeat: stretch; } </style>';   ";
  }
  sleep(5);
  // Thanks to https://stackoverflow.com/questions/28644340/how-do-i-get-base64-encoded-image-from-clipboard-in-internet-explorer/28799619 below ...
  echo "<html><head>
<title>Emoji Image Creator - RJM Programming - November, 2020 ... thanks to Google PageSpeed</title>
<meta charset='utf-8'>
<style> 

#borderimg1 { 
  border: 20px solid " . $transparent . ";
  padding: 15px;
  border-image: url(border.png) 30%;
  border-image-repeat: round;
}

#borderimg2 { 
  border: 20px solid " . $transparent . ";
  padding: 15px;
  border-image: url(border.png) 30%;
  border-image-repeat: stretch;
}

@media only screen and (max-width: 768px) {
  #borderimg1 {  border: 20px solid white;  }
  #borderimg2 {  border: 20px solid white;  }
}

#borderimg1:before { content: ''; }  

#borderimg2:before { content: ''; }  

</style>
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>
<script type='text/javascript'>

var readynow=false;
var done=false;
var btype='';

$(document).ready(function() {
  $('#editor').on('paste', function(e) {
    var orgEvent = e.originalEvent;
    for (var i = 0; i < orgEvent.clipboardData.items.length; i++) {
      if (orgEvent.clipboardData.items[i].kind == \"file\" && (('' + orgEvent.clipboardData.items[i].type).substring(0,6) == \"" . $iimage . "/\" || ('' + orgEvent.clipboardData.items[i].type).substring(0,6) == \"" . $iaudio . "/\" || ('' + orgEvent.clipboardData.items[i].type).substring(0,6) == \"" . $ivideo . "/\")) {
        var imageFile = orgEvent.clipboardData.items[i].getAsFile();
        var fileReader = new FileReader();
        btype=('' + orgEvent.clipboardData.items[i].type);
        fileReader.onloadend = function() {
          $('#result').html(fileReader.result);
          andthen(btype);
        }
        fileReader.readAsDataURL(imageFile);
        break;
      }
    }
  });
});

function andthen(intype) {
  var edih='';
  if (document.getElementById('result')) {
    if (document.getElementById('result').innerHTML == '' && document.getElementById('editor')) {
      if (document.getElementById('editor').innerHTML.indexOf(' src=\"data:') != -1) {
        document.getElementById('result').innerHTML='data:' + document.getElementById('editor').innerHTML.split(' src=\"data:')[1].split('\"')[0];
      } 
    }
    if (('' + intype).indexOf('audio') == 0) {
      done=true;
      document.getElementById('editor').innerHTML='<audio controls><source type=\"' + ('' + intype) + '\" src=\"' + document.getElementById('result').innerHTML + '\"></source></audio>';
    } else if (('' + intype).indexOf('video') == 0) {
      done=true;
      document.getElementById('editor').innerHTML='<video controls><source type=\"' + ('' + intype) + '\" src=\"' + document.getElementById('result').innerHTML + '\"></source></video>';
    } else if (document.getElementById('editor').innerHTML.indexOf('<a ') != 0) {
      edih=document.getElementById('editor').innerHTML;
      document.getElementById('editor').innerHTML='<a target=_blank href=\"' + document.getElementById('result').innerHTML + '\" title=\"Download here\" download>' + edih + '</a>';
    }
    if (!done) {
    done=true;
    document.getElementById('emoji_uncropped_image').value=document.getElementById('result').innerHTML;
    document.getElementById('isub').click();
    setTimeout(andthen, 5000);
    } else if (1 == 1) {
" . $dstyle . "
    if (('' + intype).indexOf('audio') != 0 && ('' + intype).indexOf('video') != 0) {
    document.getElementById('borderimg1').style.display='block';
    document.getElementById('borderimg1').innerHTML=(document.getElementById('borderimg1').outerHTML.split('>')[0] + '>The rain in Spain falls mainly on the plain.</div>').replace(/\</g,'&lt;').replace(/\</g,'&gt;').replace('display:','border: 20px solid " . $transparent . ";padding: 15px;border-image:URL([asBelow]);border-image-slice: 30%; border-image-repeat: round;display:');
    document.getElementById('borderimg2').style.display='block';
    document.getElementById('borderimg2').innerHTML=(document.getElementById('borderimg2').outerHTML.split('>')[0] + '>The rain in Spain falls mainly on the plain.</div>').replace(/\</g,'&lt;').replace(/\</g,'&gt;').replace('display:','border: 20px solid " . $transparent . ";padding: 15px;border-image:URL([asBelow]);border-image-slice: 20%; border-image-repeat: stretch;display:');
    document.getElementById('thone').title=' #thone { background:URL([asBelow]); background-repeat:no-repeat;  } ';
    document.getElementById('thtwo').title=' #thtwo { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL([asBelow]); background-repeat:repeat; }  ';
    document.getElementById('hthree').title=' #hthree { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL([asBelow]); background-size:cover; background-repeat:no-repeat;  } ';
    document.getElementById('result').title='  #result { background:linear-gradient(rgba(255,255,255,0.3),rgba(255,255,255,0.3)),URL([asBelow]); background-size:contain; background-repeat:no-repeat;  } ';
    document.getElementById('borderimg1').title=' #borderimg1 { border-image: url([asBelow]) 30%; border-image-repeat: round; } ';
    document.getElementById('borderimg2').title=' #borderimg2 { border-image: url([asBelow]) 20%; border-image-repeat: stretch; } ';
    readynow=true;
    setTimeout(zthen, 8000);
    }
    }
  }
}

function dorn() {
  readynow=true;
}

function zthen() {
  if (readynow) {
    downloaditize(document.getElementById('thone')); 
    downloaditize(document.getElementById('thtwo')); 
    downloaditize(document.getElementById('hthree')); 
    downloaditize(document.getElementById('borderimg1')); 
    downloaditize(document.getElementById('borderimg2')); 
    downloaditize(document.getElementById('result')); 
  } else {
    setTimeout(zthen, 1000);
  } 
}

function downloaditize(ois) {
  var xrect=ois.getBoundingClientRect(); 
  var fromc=\" style='\";
  var toc=\" style='width:\" + xrect.width + \"px;height:\" + xrect.height + \"px;\";
  var ihis='', stys=[];
  var wasihis=ois.innerHTML;
  if (wasihis.indexOf(' download') == -1) {
  if (('' + ois.id).indexOf('borderimg') == 0) {
  ihis='<html><body' + toc + \"'\" + '>' + ois.innerHTML.replace('[asBelow]', ('data:' + document.getElementById('result').innerHTML.split('data:')[1].split('</')[0].split(')')[0])).replace(' transparent',' white') + '</body></html>';
  while (ihis.indexOf(String.fromCharCode(34)) != -1) {
    ihis=ihis.replace(String.fromCharCode(34),String.fromCharCode(39));
  }
  while (wasihis.indexOf(String.fromCharCode(34)) != -1) {
    wasihis=wasihis.replace(String.fromCharCode(34),String.fromCharCode(39));
  }
  //console.log(wasihis);
  //console.log('<a download style=\"cursor:pointer;text-decoration: underline overline dotted red;\" target=_blank href=\"data:text/html,' + wasihis.replace(/\&lt\;/g,'<').replace(/\&gt\;/g,'>').replace('[asBelow]', document.getElementById('result').innerHTML).replace(' transparent',' white') + '\" title=\"Download here\">' + wasihis + '</a>');
  ois.innerHTML='<a download style=\"cursor:pointer;text-decoration: underline overline dotted red;\" target=_blank href=\"data:text/html,' + wasihis.replace(/\&lt\;/g,'<').replace(/\&gt\;/g,'>').replace('[asBelow]', document.getElementById('result').innerHTML).replace(' transparent',' white') + '\" title=\"Download here\">' + wasihis + '</a>';
  } else {
  if (('' + ois.id) == 'result') {
  ihis='<html><body>' + ois.outerHTML.replace('[asBelow]', ('data:' + document.getElementById('result').innerHTML.split('data:')[1].split('</')[0].split(')')[0])).replace(' transparent',' white').replace(' title=', ' style=').replace('{',' ').replace('}',' ').replace('#' + ('' + ois.id),' ') + '</body></html>';
  } else {
  ihis='<html><body><table><tr>' + ois.outerHTML.replace('[asBelow]', document.getElementById('result').innerHTML).replace(' transparent',' white').replace(' title=', ' style=').replace('{',' ').replace('}',' ').replace('#' + ('' + ois.id),' ') + '</tr></table></body></html>';
  }
  while (ihis.indexOf(String.fromCharCode(34)) != -1) {
    ihis=ihis.replace(String.fromCharCode(34),String.fromCharCode(39));
  }
  stys=ihis.split(\"' style='\");
  if (stys.length == 3) {
    ihis=ihis.replace(\"' style='\" + stys[2], \" \" + stys[2]);
  }
  if (('' + ois.id) != 'result') {
  console.log('<a download style=\"cursor:pointer;text-decoration: underline overline dotted red;\" target=_blank href=\"data:text/html,' + ihis.replace(fromc,toc) + '\" title=\"Download here\">' + wasihis + '</a>');
  }
  ois.innerHTML='<a download style=\"cursor:pointer;text-decoration: underline overline dotted red;\" target=_blank href=\"data:text/html,' + ihis.replace(fromc,toc) + '\" title=\"Download here\">' + wasihis + '</a>';
  }
  }
}

function checkfordel() {
  document.getElementById('mydeler').src=document.getElementById('mydeler').src.replace('emoji_mr_image=', 'emoji_rm_image=') + 'x';
  setTimeout(checkfordel,10000);
}

function doemail() {
  var emis=prompt('Please enter email address to send Email To?  (all lowercase uses client emailer where you should Paste into body of email and all numbers we shall assume you are sending an SMS, else will send an Inline HTML Email (that will not work for all email clients))', '');
  if (emis == null) { emis=''; }
  if (emis.indexOf('@') != -1 || (emis.trim() != '' && emis.replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '')) {
  if (emis.toLowerCase() == emis) {
  if (emis.indexOf('@') != -1) {
  document.getElementById('aemail').href='mailto:' + emis + '?subject=' + encodeURIComponent('My Emoji Image(s)') + '&body=' + encodeURIComponent(' ... via http://www.rjmprogramming.com.au/PHP/emoji_image.php ...' + String.fromCharCode(10));
  document.getElementById('aemail').click();
  } else {
  document.getElementById('aemail').href='sms:' + emis + '&body=' + encodeURIComponent('My Emoji Image(s)' + ' ... via http://www.rjmprogramming.com.au/PHP/emoji_image.php ... ' + String.fromCharCode(10));
  document.getElementById('aemail').click();
  }
  } else {
  var xzhr = new XMLHttpRequest();
  var xform=new FormData();
  xform.append('inline', '');
  xform.append('to', emis);
  xform.append('subject', 'My Emoji Image(s)');
  xform.append('body', '<body><a target=_blank title=\"Emoji Image Creator\" href=\"http://www.rjmprogramming.com.au/PHP/emoji_image.php\"><img src=\"' + document.getElementById('result').innerHTML + '\" title=\"Emoji Image(s)\"></img></a></body>');
  xzhr.open('post', '//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php', true);
  xzhr.send(xform);
  }
  }
}

function onlis() {
  var erect=document.getElementById(\"pem\").getBoundingClientRect(); 
  document.getElementById(\"ewidth\").value=\"\" + erect.width;  
  document.getElementById(\"eheight\").value=\"\" + erect.height; 
}
</script>
<style>
td { 
  vertical-align: top; 
}

#editor {
  width: 500px;
  min-height: 40px;
  border: solid 1px gray;
  padding: 4px;
}

#resultcnt {
  width: 100%;
  margin-top: 16px;
}

#result {
  display: block;
  max-width: 90%;
  margin: 16px 0 32px 0;
  font-size: 12px;
  color: blue;
  overflow: visible;
  word-break: break-all;
}

textarea {
  font-family: Courier New;
}

input {
  font-family: Courier New;
}

video {
  width: 100%;
}
</style>
</head>
<body onload='" . $gps . " onlis(); setTimeout(checkfordel,10000);  '><p style='font-size:256px;'>". str_replace("&#;","","&#" . str_replace(".", ";&#", str_replace("+"," ",$etext)) . ";") . "</p>
<h" . $one . " id=hthree style='color:red;position:absolute;top:0px;left:400px;'>" . $hblurb . "</h" . $one . ">
<table style='position:absolute;top:280px;left:0px;' border=1><tr><th id=thone>" . $ei . " <font size=1><a target=_blank href='./emoji_image.php' title='Back to defining emojis'>" . $cr . "</a></font><br><font size=1>(Paste Below)</font></th><th id=thtwo>Data URI</th></tr>
<tr><td colspan=2><div id=borderimg1 style=display:none;></div>
<div id=borderimg2 style=display:none;></div>
</td></tr>
<tr><td><div id='editor' contenteditable=true></div></td><td>
<div id='resultcnt'>Copied " . $imgw . " src (that you can <a style='cursor:pointer;text-decoration:underline;' onclick='doemail();' title='Email'>Email &#128231;</a>):<br>
  <div id='result'></div>
</div></td></table><iframe id=mydeler style='display:none;' src='./emoji_image.php?emoji_mr_image=" . urlencode(str_replace(";","",str_replace("&#","",str_replace(";&#",".",$gei)))) . "&suff=x'></iframe>  
<a id=aemail href='mailto:?subject=" . str_replace("+","%20",urlencode('My Emoji Image(s)')) . "&body=' style=display:none;>Email</a>
<div id=dstyle></div>
<form style=display:none; target=ifeui method=POST action=./emoji_image.php><input type=hidden name=emoji_uncropped_image id=emoji_uncropped_image value=''></input><input type=hidden id=ewidth name=ewidth value='0'></input><input type=hidden id=eheight name=eheight value='0'></input><input type=submit id=isub value=Go style=display:none;></input></form>
<iframe name=ifeui id=ifeui style=display:none; src='//www.rjmprogramming.com.au/About_Us.html'></iframe>
<p id=pem style='font-size:256px;visibility:hidden;opacity:0.1;'>" . $xgei . "</p>
</body></html>";
  //$eresult=file_get_contents("https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fwww.rjmprogramming.com.au%2FPHP%2Femoji_image.php");
  //file_put_contents('emojiimage.txt', $eresult);
  //exec("sleep 15; rm -f " . dirname(__FILE__) . "/emoji_image.txt");
} else {
  echo "<html><head>
<title>Emoji Image Creator - RJM Programming - November, 2020 ... thanks to Google PageSpeed</title><meta charset='utf-8'></head><body style='background-color:#e0e0e0;' onload=' if (window.top == window.self) { document.getElementById(\"emoji_image\").focus(); } '><h1 class=glow title='Copy (Image) from Google PageSpeed (thanks, and note to toggle between mobile and desktop tabs perhaps) and Paste via macOS Alt-PrtScr Below (for Data URI as well) or to an Image Editor that can Crop out Extraneous White Parts or Resize Image and Save (ready for Border Image or Background Image or just Image purposes)'>Emoji Image Creator</h1><h3>Thanks to <a target=_blank title='Google PageSpeed' href='https://developers.google.com/speed/pagespeed/insights/'>Google PageSpeed</a> and <a target=_blank title='Useful link, thanks' href='https://stackoverflow.com/questions/28644340/how-do-i-get-base64-encoded-image-from-clipboard-in-internet-explorer/28799619'>Stack Overflow</a> and <a target=_blank title='jQuery' href='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'>jQuery</a></h3><form method=GET action=./emoji_image.php><input type=text name=emoji_image id=emoji_image value='' placeholder=' Emoji CodePoint(s) here (or macOS Control-Command-Space) eg. 127462.127482 is compound Emoji' style='width:99%;' required></input><br><br><textarea onchange=\"if (this.value.trim().length > 0 && document.getElementById('emoji_image').value.trim().length == 0) { document.getElementById('emoji_image').value=' '; } \" name=emoji_textarea_image id=emoji_textarea_image value='' placeholder=' ... and/or rows of Emoji CodePoint(s) here (or macOS Control-Command-Space) eg. 127462.127482 is compound Emoji' cols=120 rows=10></textarea><br><br>
<input style=background-color:yellow; type=submit value='Create Image'></input>&nbsp;&nbsp;&nbsp;<input onclick=\" window.open(document.URL.split('#')[0].split('?')[0] + '?emoji_image=&emoji_uncropped_image=&video=y','_blank');  \" style=background-color:yellow; type=button id=video value='Copy Video'></input>&nbsp;&nbsp;&nbsp;<input onclick=\" window.open(document.URL.split('#')[0].split('?')[0] + '?emoji_image=&emoji_uncropped_image=&audio=y','_blank'); \" style=background-color:yellow; type=button name=audio id=audio value='Copy Audio'></input></form></body></html>"; 
}
?>
