<?php
// img_maker.php
// RJM Programming
// February, 2023
// Put in document root

function ourimagecreatefromstring() {
  if (isset($_POST['inimgdata']) && isset($_POST['inimgnum']) && str_replace('+',' ',urldecode($_POST['inimgpwd'])) == 'password') {
    $thetemp="";
    $inidis=str_replace(' ','+',urldecode($_POST['inimgdata']));
    $extis=str_replace('jpeg','jpg',explode('/', explode(';base64,', $inidis)[0])[1]);
    $sofarout=$thetemp . 'intmp' . str_replace('+',' ',urldecode($_POST['inimgnum'])) . '.' . $extis;
    file_put_contents($sofarout, base64_decode(explode(';base64,', $inidis)[1]));
  } else if (!isset($_GET['junk'])) {
    echo "<html><head>
    <script type='text/javascript'>
    var nt=''; 
    var inb='Enter password and a space before a number to append to name part of filename.';
    var formb='<form target=myiframeviac id=myformviac style=display;none; action=/img_maker.php?junk=y method=POST onsubmit=\" var pandn=prompt(' + String.fromCharCode(39) + inb + String.fromCharCode(39) + ',' + String.fromCharCode(39) + nt + String.fromCharCode(39) + '); if (pandn == null) { pandn=' + String.fromCharCode(39) + nt + String.fromCharCode(39) + '; } ' + \" document.getElementById('inimgdata').value=document.getElementById('canvaselement').toDataURL('image/jpeg',0.3);  document.getElementById('inimgpwd').value=pandn.split(String.fromCharCode(32))[0];  if (pandn.indexOf(String.fromCharCode(32)) != -1) {  document.getElementById('inimgnum').value=pandn.substring(eval(1 + pandn.indexOf(String.fromCharCode(32)))); }  return true;  \" + '\"><input type=hidden name=inimgdata id=inimgdata value=></input><input type=hidden name=inimgnum id=inimgnum value=></input><input type=hidden name=inimgpwd id=inimgpwd value=></input><input type=submit id=mysubviac value=Submit style=display:none;></input></form><iframe style=display:none; name=myiframeviac id=myiframeviac></iframe>';
    function anth() {  parent.document.getElementById('mysubviac').click();   }
    </script>
</head>
<body onload=\"   if (parent.document.getElementById('danno') && parent.document.getElementById('canvaselement')) { if (!parent.document.getElementById('myformviac')) { parent.document.getElementById('danno').innerHTML+=formb;  anth(); } else {  anth(); } } \">
</body></html>";
  }
}

ourimagecreatefromstring();
exit;

?>
