<?php
// pixellate.php
// RJM Programming
// December, 2017

$gds=[];  // animation slides
$datauris=[];
$currgds=0;
$endbody='';
$penup=false;
$reverseopacity = 0;
$zeroes = 4;
$width = 200;
$height = 200;
$rgbas=[""];
$rgbai=[-1];
$rgbac=0;
$two=2;
$lfs='';
$wlfs='';
$notme='';
$prew='';
$postw='';
$twothousand="2000";
$spacechar=' ';

if (isset($_GET['lookfor'])) {
   if (file_exists(dirname(__FILE__) . '/' . oururldecode($_GET['lookfor']))) {
     $lfs=file_get_contents(dirname(__FILE__) . '/' . oururldecode($_GET['lookfor']));
     if (strpos($lfs, "``" . server_remote_addr() . "`") !== false) {
     $xlfs=explode("`",explode("``" . server_remote_addr() . "`", $lfs)[1])[0];
     $lfs=$xlfs;
     } 
   }
   isthere(false,'circle');
   isthere(false,'arc');
   isthere(false,'coords');
   isthere(false,'mode');
   isthere(false,'width');
   isthere(false,'height');
   isthere(false,'zeroes');
   isthere(false,'size');
   isthere(false,'positive');
   isthere(false,'opacity');
   isthere(false,'url');
   isthere(false,'tarea');
   isthere(false,'duration');
   isthere(false,'rotate');
   isthere(true,'circle');
} else if (isset($_POST['lookfor'])) {
   if (file_exists(dirname(__FILE__) . '/' . oururldecode($_POST['lookfor']))) {
     $lfs=file_get_contents(dirname(__FILE__) . '/' . oururldecode($_POST['lookfor']));
     if (strpos($lfs, "``" . server_remote_addr() . "`") !== false) {
     $xlfs=explode("`",explode("``" . server_remote_addr() . "`", $lfs)[1])[0];
     $lfs=$xlfs;
     } 
   }
   isthere(false,'circle');
   isthere(false,'arc');
   isthere(false,'coords');
   isthere(false,'mode');
   isthere(false,'width');
   isthere(false,'height');
   isthere(false,'zeroes');
   isthere(false,'size');
   isthere(false,'positive');
   isthere(false,'opacity');
   isthere(false,'url');
   isthere(false,'tarea');
   isthere(false,'duration');
   isthere(false,'rotate');
   isthere(false,'raster');
   isthere(true,'circle');
}


if (isset($_GET['duration']) || isset($_POST['duration']) || isthere(false, 'duration') != '') {
   if (urldecode($_GET['duration']) != '') {
     $twothousand=(1000 * urldecode($_GET['duration']));
   } else if (urldecode($_POST['duration']) != '' || isthere(false,'duration') != '') {
     $twothousand=(1000 * urldecode(isthere(false,'duration')));
   }
}

function rotate($img1, $angle) { // thanks to https://stackoverflow.com/questions/780993/php-gd-rotate-image
    global $gd, $gds, $currgds, $x, $y, $reverseopacity, $new_width, $new_height, $reverseopacity;
    if ($angle == 0.0) return $img1;

    $width_before = imagesx($img1);
    $height_before = imagesy($img1);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
 $img1 = imagerotate($img1, $angle, imagecolorallocatealpha($img1, 255, 255, 255, $reverseopacity)); 
} else {
 $img1 = imagerotate($img1, $angle, imagecolorallocatealpha($img1, 0, 0, 0, $reverseopacity)); 
}

    //$img1 = imagescale($img1, 0.7, 0.7);
    $new_width = imagesx($img1); // whese dimensions are
    $new_height = imagesy($img1);// the scaled ones (by imagerotate)
    $thumb = @imagecreatetruecolor($x, $y);
    imagecopyresized($thumb, $img1, 0, 0, 0, 0, $x, $y, $new_width, $new_height);
    imagedestroy($img1);

    //but imagerotate scales, so we clip to the original size

    $img2 = @imagecreatetruecolor($x, $y);
    $new_width = imagesx($thumb); //$img1); // whese dimensions are
    $new_height = imagesy($thumb); //$img1);// the scaled ones (by imagerotate)
    imagecopyresampled(
        $img2, $thumb, //$img1,
        0, 0,
        ($new_width-$x)/2,
        ($new_height-$y)/2,
        $x,
        $y,
        $x,
        $y
    );
    imagedestroy($thumb); //$img1);
    //$new_width = imagesx($img2);  // ?
    //$new_height = imagesy($img2); // ?
    $gd = $img2;
    // now img1 is center rotated and maintains original size
    return $gd;
}

function gdback($ggd) {
  global $gd, $gds, $currgds, $x, $y, $reverseopacity, $precbits;
  if (sizeof($gds) != 0) {
    if ($currgds > 0) {
      if (sizeof($gds) > $currgds) {
        $gd=$gds[$currgds];
        return $gds[$currgds];
      } else {
        if (1 == 2) {
        $gds[sizeof($gds)] = $ggd;
        } else {
        $gds[$currgds] = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gds[$currgds], 255, 255, 255, $reverseopacity); 
imagefill($gds[$currgds],0,0,$wb);
}
        }
        return $gds[$currgds];
        //$gd=$gds[$currgds];
        $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
      }
    }
  } 
  return $gd;
}

function oururldecode($wh) {
  if (strpos(urldecode($wh), ".") !== false) {
    return urldecode($wh);
  } else {
    return urldecode($wh) . ".php";
  }
}

function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    return $rma;
}

function our_file_put_contents($fn, $prec, $cis, $postc) { 
  if (file_exists($fn)) {
    $tbits=explode("``" . server_remote_addr() . "`", file_get_contents($fn));
    if (sizeof($tbits) == 1) {
    $xprec="<" . "?" . "php \n \$x='``" . server_remote_addr() . "`";
    $xpostc="&" . "`'; \n ?" . "> \n<html><body><p>Hello Possums!</p></body></html>";
    file_put_contents($fn, $xprec . $cis . $xpostc);
    } else {
    $xprec=$tbits[0] . "``" . server_remote_addr() . "`";
    if (substr($tbits[1], 0, 1) == "`") {
    $xpostc=$tbits[1];
    } else if (strpos($tbits[1], "`") !== false) {
    $xpostc=substr($tbits[1], (strlen(explode("`", $tbits[1])[0]) - 1));
    } else {
    $xpostc=$tbits[1];
    }
    file_put_contents($fn, $xprec . $cis . $xpostc);
    }
  } else {
    $xprec="<" . "?" . "php \n \$x='``" . server_remote_addr() . "`";
    $xpostc="&" . "`'; \n ?" . "> \n<html><body><p>Hello Possums!</p></body></html>";
    file_put_contents($fn, $xprec . $cis . $xpostc);
  }
}

function isthere($fpc,$what) {
 global $lfs, $wlfs, $notme, $prew, $postw;
 if (isset($_POST[$what])) {
   if (strpos($wlfs, $what . "=") === false && $what != "lookfor" && $what != "mode") {
     if ($_POST[$what] != "") {
     if ($wlfs == '') {
       if (!isset($_POST['width']) && !isset($_POST['height'])) {
       $wlfs='?width=850&height=600&' . $what . '=' . $_POST[$what];
       } else if (!isset($_POST['width'])) {
       $wlfs='?width=850&' . $what . '=' . $_POST[$what];
       } else if (!isset($_POST['height'])) {
       $wlfs='?height=600&' . $what . '=' . $_POST[$what];
       } else {
       $wlfs='?' . $what . '=' . $_POST[$what];
       }
     } else {
       $wlfs.='&' . $what . '=' . $_POST[$what];
     }
     if (isset($_GET['lookfor'])) {
       if ($wlfs != '') our_file_put_contents(dirname(__FILE__) . '/' . oururldecode($_GET['lookfor']), $prew, $wlfs, $postw);
     } else if (isset($_POST['lookfor'])) {
       if ($wlfs != '') our_file_put_contents(dirname(__FILE__) . '/' . oururldecode($_POST['lookfor']), $prew, $wlfs, $postw);
     }
     } 
   }
   return $_POST[$what];
 } else if (isset($_GET['lookfor'])) {
   if (strpos($lfs, $what . "=") !== false) {
     //echo $what . "==" . urldecode(explode("&",explode($what . "=", ($lfs . "&"))[1])[0]);
     //exit;
     //if ($fpc && $wlfs != '') our_file_put_contents(dirname(__FILE__) . '/' . oururldecode($_GET['lookfor']), $prew, $wlfs, $postw);
     return explode("&",explode($what . "=", ($lfs . "&"))[1])[0];
   } else {
     //if ($fpc && $wlfs != '') our_file_put_contents(dirname(__FILE__) . '/' . oururldecode($_GET['lookfor']), $prew, $wlfs, $postw);
     return '';
   }
 } else if (isset($_POST['lookfor'])) {
   if (strpos($lfs, $what . "=") !== false) {
     //echo $what . "=" . urldecode(explode("&",explode($what . "=", ($lfs . "&"))[1])[0]);
     //exit;
     //if ($fpc && $wlfs != '') our_file_put_contents(dirname(__FILE__) . '/' . oururldecode($_POST['lookfor']), $prew, $wlfs, $postw);
     return explode("&",explode($what . "=", ($lfs . "&"))[1])[0];
   } else {
     //if ($fpc && $wlfs != '') our_file_put_contents(dirname(__FILE__) . '/' . oururldecode($_POST['lookfor']), $prew, $wlfs, $postw);
     return '';
   }
 } 
}

function huhpenup($inth) {
  global $penup;
  if (strpos($inth,"+") !== false) {
    $penup=true;
  } else if (strlen((" " . trim($inth))) == strlen($inth)) {
    $penup=true;
  }
  return str_replace(" ","",str_replace("+","",$inth));
}

function ourimagesetpixelline($pgd,$px,$py,$px2,$py2,$pred) { // rasterize
global $penup;
if (!$penup) {
$llen=pow((($px - $px2) * ($px - $px2) + ($py - $py2) * ($py - $py2)), 0.5);
$sofar=-1.0;
while ($sofar < $llen) {
if ($sofar < 0.0) {
  $sofar=0.0;
  $npx=$px;
  $npy=$py;
} else if (($sofar + 1.0) > $llen) {
  $npx=$px2;
  $npy=$py2;
} else {
  $npx=round($px + ($px2 - $px) * $sofar / $llen);
  $npy=round($py + ($py2 - $py) * $sofar / $llen);
}
if (isset($_GET['size'])) {
  for ($ipx=($npx - $_GET['size']); $ipx<=($npx + $_GET['size']); $ipx++) {
  for ($ipy=($npy - $_GET['size']); $ipy<=($npy + $_GET['size']); $ipy++) {
  imagesetpixel($pgd,$ipx,$ipy,$pred);
  }
  }
} else if (isset($_POST['size']) || isthere(false,'size') != '') {
  for ($ipx=($npx - isthere(false,'size')); $ipx<=($npx + isthere(false,'size')); $ipx++) {
  for ($ipy=($npy - isthere(false,'size')); $ipy<=($npy + isthere(false,'size')); $ipy++) {
  imagesetpixel($pgd,$ipx,$ipy,$pred);
  }
  }
} else {
  imagesetpixel($pgd,$npx,$npy,$pred);
}
$sofar += 1.0;
}
}
}

function ourimagesetpixel($pgd,$px,$py,$pred) {
if (isset($_GET['size'])) {
  for ($ipx=($px - $_GET['size']); $ipx<=($px + $_GET['size']); $ipx++) {
  for ($ipy=($py - $_GET['size']); $ipy<=($py + $_GET['size']); $ipy++) {
  imagesetpixel($pgd,$ipx,$ipy,$pred);
  }
  }
} else if (isset($_POST['size']) || isthere(false,'size') != '') {
  for ($ipx=($px - isthere(false,'size')); $ipx<=($px + isthere(false,'size')); $ipx++) {
  for ($ipy=($py - isthere(false,'size')); $ipy<=($py + isthere(false,'size')); $ipy++) {
  imagesetpixel($pgd,$ipx,$ipy,$pred);
  }
  }
} else {
  imagesetpixel($pgd,$px,$py,$pred);
}
}

function modeideas($ingd, $parentdot, $midbit, $mprefix, $msuffix) {
global $gds, $currgds, $endbody, $datauris, $twothousand;
ob_start(); 
imagepng($ingd);
$image_data = ob_get_contents(); 
ob_end_clean(); 
imagedestroy($ingd);
$image_data_base64 = base64_encode($image_data);
if (sizeof($gds) > 0) { // animation candidate
  if ($currgds >= 0) {
    $datauris[sizeof($datauris)]=$image_data_base64;
    $currgds=-1;
    if ($endbody == '') {
      $endbody="<sc" . "ript type='text/javascript'> \n var currgds=0; function toggle() { if (currgds == " . (-1 - ($currgds)) . ") { " . $parentdot . "document." . $midbit . "=" . $mprefix . "'data:image/png;base64," . $datauris[(-1 - ($currgds))] . "'" . $msuffix . "; } currgds=eval((currgds + 1) % " . sizeof($gds) . ");  setTimeout(toggle," . $twothousand . "); } toggle(); </sc" . "ript> \n";
    }
    for ($iii=1; $iii<sizeof($gds); $iii++) {
    $currgds--;
ob_start(); 
imagepng($gds[$iii]);
$image_data = ob_get_contents(); 
ob_end_clean(); 
imagedestroy($gds[$iii]);
$image_data_base64 = base64_encode($image_data);
    $datauris[sizeof($datauris)]=$image_data_base64;
    if (strpos($endbody, " if (currgds == " . (-1 - ($currgds)) . ")") === false) {
      $endbody=str_replace("} currgds=eval((currgds", "} else if (currgds == " . (-1 - ($currgds)) . ") { " . $parentdot . "document." . $midbit . "=" . $mprefix . "'data:image/png;base64," . $datauris[(-1 - ($currgds))] . "'" . $msuffix . "; } currgds=eval((currgds", $endbody);
    }
    }
    return $datauris[0];
  }
}
return $image_data_base64;
}

if (isset($_GET['width'])) {
  $width = $_GET['width'];
} else if (isset($_POST['width']) || isthere(false,'width') != '') {
  $width = isthere(false,'width');
}
if (isset($_GET['height'])) {
  if (str_replace(" ","",$_GET['height']) != $_GET['height']) $spacechar='';
  $height = str_replace(" ","",$_GET['height']);
} else if (isset($_POST['height']) || isthere(false,'height') != '') {
  if (str_replace(" ","",isthere(false,'height')) != isthere(false,'height')) $spacechar='';
  $height = str_replace(" ","",isthere(false,'height'));
}
if (isset($_GET['zeroes'])) {
  $zeroes = $_GET['zeroes'];
} else if (isset($_POST['zeroes']) || isthere(false,'zeroes') != '') {
  $zeroes = isthere(false,'zeroes');
}
if (isset($_GET['opacity'])) {
  $op = urldecode($_GET['opacity']);
  $reverseopacity = floor(127.0 - ($op * 127.0));
} else if (isset($_POST['opacity']) || isthere(false,'opacity') != '') {
  $op = urldecode(isthere(false,'opacity'));
  $reverseopacity = floor(127.0 - ($op * 127.0));
}

$x = $width;
$y = $height;
$new_width = $width;
$new_height = $height;
$howmany = 1;
if ($zeroes < 0) {
  $howmany = 0;
} else {
for ($i = 0; $i < $zeroes; $i++) {
  $howmany *= 10;
}
}

$gd = imagecreatetruecolor($x, $y);
$prevgd=$gd;

if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
imagefill(gdback($gd),0,0,$wb);
//imagecopyresampled(gdback($gd), $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height);
}
 
$corners[0] = array('x' => ($width / 2), 'y' =>  10);
$corners[1] = array('x' =>   0, 'y' => ($height - 10));
$corners[2] = array('x' => $width, 'y' => ($height - 10));

$red = imagecolorallocatealpha(gdback($gd), 255, 0, 0, $reverseopacity); 
$xyarray=[];
$factor=(pi() / 180.0);

if (isset($_GET['circle'])) {
  $currgds=0;
  if ($currgds < sizeof($gds)) {
      $gd=$gds[$currgds];
  }
  $precbits=explode("|",urldecode($_GET['circle']));
  for ($ipcb=0; $ipcb<sizeof($precbits); $ipcb++) {
  if ($precbits[$ipcb] == '') {
    $precbits[$ipcb]="0,0,0";
  }
  if ($precbits[$ipcb] != '') {
$xyarray=[];
  $cbits=explode(",",$precbits[$ipcb]);
  $joff=0;
  $koff=0;
  for ($ioff=$joff; $ioff<sizeof($cbits); $ioff+=3) {
  $prefix='';
  if (sizeof($cbits) >= 3) {
    for ($a=0.0; $a<=360.0; $a+=1.0) {
      if (isset($_GET['arc'])) {
        if (strpos(urldecode($_GET['arc']), ",") !== false) {
        $prefix='';
        if ((0.0 + $a) < (0.0 + explode(",",urldecode($_GET['arc']))[0])) $prefix='+';
        if ((0.0 + $a) > (0.0 + explode(",",urldecode($_GET['arc']))[1])) $prefix='+';
        } else {
        if ((0.0 + $a) > (0.0 + urldecode($_GET['arc']))) $prefix='+';
        }
      }
      if (strpos($cbits[0 + $ioff + $koff],"rgb") !== false && strpos($cbits[0 + $ioff + $koff],"(") !== false) {
        if ($rgbai[$rgbac] < 0) {
          $rgbas[$rgbac] = $cbits[0 + $ioff + $koff];
          $rgbai[$rgbac] = sizeof($xyarray);
        } else {
          $rgbas[sizeof($rgbai)] = $cbits[0 + $ioff + $koff];
          $rgbai[sizeof($rgbai)] = sizeof($xyarray);
        } 
        $koff++;
      }
      $xyarray[sizeof($xyarray)] = $prefix . ($cbits[0 + $ioff + $koff] + sin($a * $factor) * $cbits[2 + $ioff + $koff]);
      $xyarray[sizeof($xyarray)] = $prefix . ($cbits[1 + $ioff + $koff] - cos($a * $factor) * $cbits[2 + $ioff + $koff]);
    }
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$red = imagecolorallocatealpha(gdback($gd), 0, 0, 0, $reverseopacity); 
} else {
$red = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
}
for ($i = 0; $i < (sizeof($xyarray) - $two); $i+=2) {
  $penup=false;
  if ($rgbai[$rgbac] == $i) {
    $rbits=explode(":",explode(")",explode("(",$rgbas[$rgbac])[1])[0]);
    if (sizeof($rbits) >= 4) {
    $reverseopacity=$rbits[3];
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    } else if (sizeof($rbits) >= 3) {
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    }
    if (($rgbac + 1) > sizeof($rgbas)) {
      $rgbas[sizeof($rgbai)] = "";
      $rgbai[sizeof($rgbai)] = -1;
    }
    $rgbac++;
  }
  ourimagesetpixelline(gdback($gd), round(huhpenup($xyarray[$i])),round(huhpenup($xyarray[$i + 1])), round(huhpenup($xyarray[(($i + 2) % sizeof($xyarray))])),round(huhpenup($xyarray[(($i + 3) % sizeof($xyarray))])), $red);
  //$red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
}
$xyarray=[];
  }
  }
  }

if (($ipcb + 1) < sizeof($precbits)) {  // animation candidate
   if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else if (sizeof($gds) == 0)  {
     $gds[sizeof($gds)]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   } else if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else {
     $gds[sizeof($gds) - 1]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   }
   $currgds++;
$xyarray=[];
}

  
  }
} else if (isset($_POST['circle']) || isthere(false,'circle') != '') {
  $currgds=0;
  if ($currgds < sizeof($gds)) {
      $gd=$gds[$currgds];
  }
  $precbits=explode("|",urldecode(isthere(false,'circle')));
  for ($ipcb=0; $ipcb<sizeof($precbits); $ipcb++) {
  if ($precbits[$ipcb] == '') {
    $precbits[$ipcb]="0,0,0";
  }
  if ($precbits[$ipcb] != '') {
$xyarray=[];
  $cbits=explode(",",$precbits[$ipcb]);
  $joff=0;
  $koff=0;
  for ($ioff=$joff; $ioff<sizeof($cbits); $ioff+=3) {
  $prefix='';
  if (sizeof($cbits) >= 3) {
    for ($a=0.0; $a<=360.0; $a+=1.0) {
      if (isset($_POST['arc']) || isthere(false,'arc') != '') {
        //if (strpos(urldecode($_POST['arc']), ",") !== false) {
        if (strpos(urldecode(isthere(false,'arc')), ",") !== false) {
        $prefix='';
        if ((0.0 + $a) < (0.0 + explode(",",urldecode(isthere(false,'arc')))[0])) $prefix='+';
        if ((0.0 + $a) > (0.0 + explode(",",urldecode(isthere(false,'arc')))[1])) $prefix='+';
        } else {
        if ((0.0 + $a) > (0.0 + urldecode(isthere(false,'arc')))) $prefix='+';
        }
      }
      if (strpos($cbits[0 + $ioff + $koff],"rgb") !== false && strpos($cbits[0 + $ioff + $koff],"(") !== false) {
        if ($rgbai[$rgbac] < 0) {
          $rgbas[$rgbac] = $cbits[0 + $ioff + $koff];
          $rgbai[$rgbac] = sizeof($xyarray);
          //echo $cbits[0 + $ioff + $koff];
          //exit;
        } else {
          $rgbas[sizeof($rgbai)] = $cbits[0 + $ioff + $koff];
          $rgbai[sizeof($rgbai)] = sizeof($xyarray);
        } 
        $koff++;
      }
      $xyarray[sizeof($xyarray)] = $prefix . ($cbits[0 + $ioff + $koff] + sin($a * $factor) * $cbits[2 + $ioff + $koff]);
      $xyarray[sizeof($xyarray)] = $prefix . ($cbits[1 + $ioff + $koff] - cos($a * $factor) * $cbits[2 + $ioff + $koff]);
    }
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$red = imagecolorallocatealpha(gdback($gd), 0, 0, 0, $reverseopacity); 
} else {
$red = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
}
for ($i = 0; $i < (sizeof($xyarray) - $two); $i+=2) {
  $penup=false;
  if ($rgbai[$rgbac] == $i) {
    $rbits=explode(":",explode(")",explode("(",$rgbas[$rgbac])[1])[0]);
    if (sizeof($rbits) >= 4) {
    $reverseopacity=$rbits[3];
$red = imagecolorallocatealpha(gdback($gd), str_replace("rgba(","",$rbits[0]), $rbits[1], $rbits[2], $reverseopacity); 
    } else if (sizeof($rbits) >= 3) {
    //echo $rbits[0];
    //exit;
$red = imagecolorallocatealpha(gdback($gd), str_replace("rgba(","",$rbits[0]), $rbits[1], $rbits[2], $reverseopacity); 
    }
    if (($rgbac + 1) > sizeof($rgbas)) {
      $rgbas[sizeof($rgbai)] = "";
      $rgbai[sizeof($rgbai)] = -1;
    }
    $rgbac++;
  }
  ourimagesetpixelline(gdback($gd), round(huhpenup($xyarray[$i])),round(huhpenup($xyarray[$i + 1])), round(huhpenup($xyarray[(($i + 2) % sizeof($xyarray))])),round(huhpenup($xyarray[(($i + 3) % sizeof($xyarray))])), $red);
  //$red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
}
$xyarray=[];
  }
  }
  }

if (($ipcb + 1) < sizeof($precbits)) {  // animation candidate
   if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else if (sizeof($gds) == 0)  {
     $gds[sizeof($gds)]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   } else if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else {
     $gds[sizeof($gds) - 1]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   }
   $currgds++;
$xyarray=[];
}

  
  
  }
}

$penup=false;
$rgbas=[""];
$rgbai=[-1];
$rgbac=0;
$koff=0;
$axyarray=[];

if (isset($_GET['tarea']) || isset($_GET['url'])) {
  $currgds=0;
  if ($currgds < sizeof($gds)) {
      $gd=$gds[$currgds];
  }
  $pregm='';
  $postgm='';
  $gm='';
  if (isset($_GET['url']) && isset($_GET['tarea'])) {
  if ($_GET['url'] != '') {
  $gm=strtolower(file_get_contents(urldecode($_GET['url'])));
  $postgm=' ';
  } else {
  $gm=strtolower(urldecode($_GET['tarea']));
  }
  } else if (isset($_GET['url']) && !isset($_GET['tarea'])) {
  $gm=strtolower(file_get_contents(urldecode($_GET['url'])));
  $postgm=' ';
  } else if (!isset($_GET['url']) && isset($_GET['tarea'])) {
  $gm=strtolower(urldecode($_GET['tarea']));
  } else if (isset($_GET['tarea'])) {
  $gm=strtolower(urldecode($_GET['tarea']));
  }
  if (strpos($gm, ' coords=') === false && strpos($gm, ',') !== false && $postgm == '') {
   $pregm='  coords="';
   $postgm=str_replace(';','"  coords="',$gm) . '"';
   $gm=$postgm;
   $postgm='';
  }
  $gms=explode("</map>",str_replace("|","</map>",$gm));
  $igms=sizeof($gms);
  if ($igms > 1) $igms--;
  for ($ii=0; $ii<$igms; $ii++) {
  $acoords = explode(' coords="', str_replace(" coords='",' coords="',str_replace('RGB(','rgba(',str_replace('RGBA(','rgba(',str_replace('rgb(','rgba(',($pregm . $gms[$ii] . $postgm))))));
  $dstr="";
  $delim="";
  for ($i=1; $i<sizeof($acoords); $i++) {
  $inq=explode("'",explode('"',$acoords[$i])[0])[0];
  $inqs=explode(",",$inq);
  if (strpos($acoords[-1 + $i], 'rgba(') !== false && strpos($acoords[-1 + $i], ')') !== false) {
  $huhrs=explode('rgba(', $acoords[-1 + $i]);
  $dstr.='rgba(' . str_replace(',',':',$huhrs[-1 + sizeof($huhrs)]) . '),';
  }
  if (sizeof($inqs) == 4 && strpos(strtolower($acoords[-1 + $i]), ' shape="rect"') !== false) {
  $dstr.=($delim . $inqs[0] . ',' . $inqs[1] . ',' . $inqs[0] . ',' . $inqs[3] . ',' . $inqs[2] . ',' . $inqs[3] . ',' . $inqs[2] . ',' . $inqs[1] . ',' . $inqs[0] . ',' . $inqs[1]);
  } else {
  $dstr.=($delim . $inq);
  }
  $delim="+0,0,";
  }
  $axyarray=explode(",", $dstr);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$red = imagecolorallocatealpha(gdback($gd), 0, 0, 0, $reverseopacity); 
} else {
$red = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
}
for ($i = 0; $i < sizeof($axyarray); $i++) {
      if (strpos($axyarray[$i],"rgb") !== false && strpos($axyarray[$i],"(") !== false) {
        if ($rgbai[$rgbac] < 0) {
          $rgbas[$rgbac] = $axyarray[$i];
          $rgbai[$rgbac] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } else {
          $rgbas[sizeof($rgbai)] = $axyarray[$i];
          $rgbai[sizeof($rgbai)] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } 
      } else {
        $xyarray[sizeof($xyarray)] = $axyarray[$i];
      }
}
for ($i = 0; $i < (sizeof($xyarray) - $two); $i+=2) {
  $penup=false;
  if ($rgbai[$rgbac] == $i) {
    $rbits=explode(":",explode(")",explode("(",$rgbas[$rgbac])[1])[0]);
    if (sizeof($rbits) >= 4) {
    $reverseopacity=$rbits[3];
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    } else if (sizeof($rbits) >= 3) {
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    }
    if (($rgbac + 1) > sizeof($rgbas)) {
      $rgbas[sizeof($rgbai)] = "";
      $rgbai[sizeof($rgbai)] = -1;
    }
    $rgbac++;
  }
  ourimagesetpixelline(gdback($gd), round(huhpenup($xyarray[$i])),round(huhpenup($xyarray[$i + 1])), round(huhpenup($xyarray[(($i + 2) % sizeof($xyarray))])),round(huhpenup($xyarray[(($i + 3) % sizeof($xyarray))])), $red);
  //$red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
}
}
} else if (isset($_POST['tarea']) || isset($_POST['url']) || isthere(false,'tarea') != '' || isthere(false,'url') != '') {
  $pregm='';
  $postgm='';
  $gm='';
  if ((isset($_POST['url']) && isset($_POST['tarea'])) || (isthere(false,'url') != '' && isthere(false,'tarea') != '')) {
  if (urldecode(isthere(false,'url')) != '') {
  $gm=strtolower(file_get_contents(urldecode(isthere(false,'url'))));
  $postgm=' ';
  } else {
  $gm=strtolower(urldecode(isthere(false,'tarea')));
  }
  } else if ((isset($_POST['url']) && !isset($_POST['tarea']))  || (isthere(false,'url') != '' && isthere(false,'tarea') == '')) {
  $gm=strtolower(file_get_contents(urldecode(isthere(false,'url'))));
  $postgm=' ';
  } else if ((!isset($_POST['url']) && isset($_POST['tarea'])) || (isthere(false,'url') == '' && isthere(false,'tarea') != '')) {
  $gm=strtolower(urldecode(isthere(false,'tarea')));
  } else if (isset($_POST['tarea']) || isthere(false,'tarea') != '') {
  $gm=strtolower(urldecode(isthere(false,'tarea')));
  }
  if (strpos($gm, ' coords=') === false && strpos($gm, ',') !== false && $postgm == '') {
   $pregm='  coords="';
   $postgm=str_replace(';','"  coords="',$gm) . '"';
   $gm=$postgm;
   $postgm='';
  }
  $gms=explode("</map>",$gm);
  $igms=sizeof($gms);
  if ($igms > 1) $igms--;
  for ($ii=0; $ii<$igms; $ii++) {
  $acoords = explode(' coords="', str_replace(" coords='",' coords="',str_replace('RGB(','rgba(',str_replace('RGBA(','rgba(',str_replace('rgb(','rgba(',($pregm . $gms[$ii] . $postgm))))));
  $dstr="";
  $delim="";
  for ($i=1; $i<sizeof($acoords); $i++) {
  $inq=explode("'",explode('"',$acoords[$i])[0])[0];
  $inqs=explode(",",$inq);
  if (strpos($acoords[-1 + $i], 'rgba(') !== false && strpos($acoords[-1 + $i], ')') !== false) {
  $huhrs=explode('rgba(', $acoords[-1 + $i]);
  $dstr.='rgba(' . str_replace(',',':',$huhrs[-1 + sizeof($huhrs)]) . '),';
  }
  if (sizeof($inqs) == 4 && strpos(strtolower($acoords[-1 + $i]), ' shape="rect"') !== false) {
  $dstr.=($delim . $inqs[0] . ',' . $inqs[1] . ',' . $inqs[0] . ',' . $inqs[3] . ',' . $inqs[2] . ',' . $inqs[3] . ',' . $inqs[2] . ',' . $inqs[1] . ',' . $inqs[0] . ',' . $inqs[1]);
  } else {
  $dstr.=($delim . $inq);
  }
  $delim="+0,0,";
  }
  $axyarray=explode(",", $dstr);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$red = imagecolorallocatealpha(gdback($gd), 0, 0, 0, $reverseopacity); 
} else {
$red = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
}
for ($i = 0; $i < sizeof($axyarray); $i++) {
      if (strpos($axyarray[$i],"rgb") !== false && strpos($axyarray[$i],"(") !== false) {
        if ($rgbai[$rgbac] < 0) {
          $rgbas[$rgbac] = $axyarray[$i];
          $rgbai[$rgbac] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } else {
          $rgbas[sizeof($rgbai)] = $axyarray[$i];
          $rgbai[sizeof($rgbai)] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } 
      } else {
        $xyarray[sizeof($xyarray)] = $axyarray[$i];
      }
}
for ($i = 0; $i < (sizeof($xyarray) - $two); $i+=2) {
  $penup=false;
  if ($rgbai[$rgbac] == $i) {
    $rbits=explode(":",explode(")",explode("(",$rgbas[$rgbac])[1])[0]);
    if (sizeof($rbits) >= 4) {
    $reverseopacity=$rbits[3];
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    } else if (sizeof($rbits) >= 3) {
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    }
    if (($rgbac + 1) > sizeof($rgbas)) {
      $rgbas[sizeof($rgbai)] = "";
      $rgbai[sizeof($rgbai)] = -1;
    }
    $rgbac++;
  }
  ourimagesetpixelline(gdback($gd), round(huhpenup($xyarray[$i])),round(huhpenup($xyarray[$i + 1])), round(huhpenup($xyarray[(($i + 2) % sizeof($xyarray))])),round(huhpenup($xyarray[(($i + 3) % sizeof($xyarray))])), $red);
  //$red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
}
}

if (($ii + 1) < $igms) {  // animation candidate
   if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else if (sizeof($gds) == 0)  {
     $gds[sizeof($gds)]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   } else if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else {
     $gds[sizeof($gds) - 1]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   }
   $currgds++;
$xyarray=[];
}

}

$penup=false;
$rgbas=[""];
$rgbai=[-1];
$rgbac=0;
$koff=0;
$axyarray=[];
$precbits=[];

if (isset($_GET['coords']) || isset($_GET['closecoords']) || sizeof($xyarray) > 0) {
  $currgds=0;
  if ($currgds < sizeof($gds)) {
      $gd=$gds[$currgds];
  }
  
  
if (isset($_GET['closecoords'])) {
 if (sizeof($xyarray) == 0) {
 if (isset($_GET['coords'])) {
   $precbits=explode("|",urldecode($_GET['coords']));
 } else {
   $precbits=explode("|",urldecode($_GET['closecoords']));
 }
 }
} else if (sizeof($xyarray) == 0) {
   $precbits=explode("|",urldecode($_GET['coords']));
}
  
  
for ($ipcb=0; $ipcb<sizeof($precbits); $ipcb++) {
$two=2;
if (isset($_GET['closecoords'])) {
 $two=0;
 if (sizeof($xyarray) == 0) {
 if (isset($_GET['coords'])) {
 $xyarray=[];
 $axyarray=explode(",",str_replace(";",",+0,0,",$precbits[$ipcb]));
 } else {
 $xyarray=[];
 $axyarray=explode(",",str_replace(";",",+0,0,",$precbits[$ipcb]));
 }
 }
} else if (sizeof($xyarray) == 0) {
 $xyarray=[];
 $axyarray=explode(",",str_replace(";",",+0,0,",$precbits[$ipcb]));
}
  if ($precbits[$ipcb] == '') {
    $precbits[$ipcb]="0,0,0,0";
  }
  if ($precbits[$ipcb] != '') {
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$red = imagecolorallocatealpha(gdback($gd), 0, 0, 0, $reverseopacity); 
} else {
$red = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
}
for ($i = 0; $i < sizeof($axyarray); $i++) {
      if (strpos($axyarray[$i],"rgb") !== false && strpos($axyarray[$i],"(") !== false) {
        if ($rgbai[$rgbac] < 0) {
          $rgbas[$rgbac] = $axyarray[$i];
          $rgbai[$rgbac] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } else {
          $rgbas[sizeof($rgbai)] = $axyarray[$i];
          $rgbai[sizeof($rgbai)] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } 
      } else {
        $xyarray[sizeof($xyarray)] = $axyarray[$i];
      }
}
for ($i = 0; $i < (sizeof($xyarray) - $two); $i+=2) {
  $penup=false;
  if ($rgbai[$rgbac] == $i) {
    $rbits=explode(":",explode(")",explode("(",$rgbas[$rgbac])[1])[0]);
    if (sizeof($rbits) >= 4) {
    $reverseopacity=$rbits[3];
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    } else if (sizeof($rbits) >= 3) {
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    }
    if (($rgbac + 1) > sizeof($rgbas)) {
      $rgbas[sizeof($rgbai)] = "";
      $rgbai[sizeof($rgbai)] = -1;
    }
    $rgbac++;
  }
  ourimagesetpixelline(gdback($gd), round(huhpenup($xyarray[$i])),round(huhpenup($xyarray[$i + 1])), round(huhpenup($xyarray[(($i + 2) % sizeof($xyarray))])),round(huhpenup($xyarray[(($i + 3) % sizeof($xyarray))])), $red);
  //$red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
}
}

if (($ipcb + 1) < sizeof($precbits)) {  // animation candidate
   if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else if (sizeof($gds) == 0)  {
     $gds[sizeof($gds)]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   } else if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else {
     $gds[sizeof($gds) - 1]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   }
   $currgds++;
$xyarray=[];
}

  
}
} else if (isset($_POST['coords']) || isset($_POST['closecoords']) || isthere(false,'coords') != '' || isthere(false,'closecoords') != '') {

$penup=false;
$rgbas=[""];
$rgbai=[-1];
$rgbac=0;
$koff=0;
$axyarray=[];
$precbits=[];

  $xyarray=[];
  $currgds=0;
  if ($currgds < sizeof($gds)) {
      $gd=$gds[$currgds];
  }
  
  
if (isset($_POST['closecoords']) || isthere(false,'closecoords') != '') {
 if (sizeof($xyarray) == 0) {
 if (isset($_POST['coords']) || isthere(false,'coords') != '') {
   $precbits=explode("|",urldecode(isthere(false,'coords')));
 } else {
   $precbits=explode("|",urldecode(isthere(false,'closecoords')));
 }
 }
} else if (sizeof($xyarray) == 0) {
   $precbits=explode("|",urldecode(isthere(false,'coords')));
}
  
for ($ipcb=0; $ipcb<sizeof($precbits); $ipcb++) {


$two=2;
if (isset($_POST['closecoords']) || isthere(false,'closecoords') != '') {
 $two=0;
 if (sizeof($xyarray) == 0) {
 if (isset($_POST['coords']) || isthere(false,'coords') != '') {
 $axyarray=explode(",",str_replace(";",",+0,0,",$precbits[$ipcb]));
 $xyarray=[];
 } else {
 $axyarray=explode(",",str_replace(";",",+0,0,",$precbits[$ipcb]));
 $xyarray=[];
 }
 }
} else if (sizeof($xyarray) == 0) {
 $axyarray=explode(",",str_replace(";",",+0,0,",$precbits[$ipcb]));
 $xyarray=[];
}


for ($i = 0; $i < sizeof($axyarray); $i++) {
      if (strpos($axyarray[$i],"rgb") !== false && strpos($axyarray[$i],"(") !== false) {
        if ($rgbai[$rgbac] < 0) {
          $rgbas[$rgbac] = $axyarray[$i];
          $rgbai[$rgbac] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } else {
          $rgbas[sizeof($rgbai)] = $axyarray[$i];
          $rgbai[sizeof($rgbai)] = sizeof($xyarray) - (sizeof($xyarray) % 2);
        } 
      } else {
        $xyarray[sizeof($xyarray)] = $axyarray[$i];
      }
}



  if ($precbits[$ipcb] == '') {
    $precbits[$ipcb]="0,0,0,0";
  }
if ($precbits[$ipcb] != '') {


if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$red = imagecolorallocatealpha(gdback($gd), 0, 0, 0, $reverseopacity); 
} else {
$red = imagecolorallocatealpha(gdback($gd), 255, 255, 255, $reverseopacity); 
}
for ($i = 0; $i < (sizeof($xyarray) - $two); $i+=2) {
  $penup=false;
  if ($rgbai[$rgbac] == $i) {
    $rbits=explode(":",explode(")",explode("(",$rgbas[$rgbac])[1])[0]);
    if (sizeof($rbits) >= 4) {
    $reverseopacity=$rbits[3];
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    } else if (sizeof($rbits) >= 3) {
$red = imagecolorallocatealpha(gdback($gd), $rbits[0], $rbits[1], $rbits[2], $reverseopacity); 
    }
    if (($rgbac + 1) > sizeof($rgbas)) {
      $rgbas[sizeof($rgbai)] = "";
      $rgbai[sizeof($rgbai)] = -1;
    }
    $rgbac++;
  }
  ourimagesetpixelline(gdback($gd), round(huhpenup($xyarray[$i])),round(huhpenup($xyarray[$i + 1])), round(huhpenup($xyarray[(($i + 2) % sizeof($xyarray))])),round(huhpenup($xyarray[(($i + 3) % sizeof($xyarray))])), $red);
  //$red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
}

}


if (($ipcb + 1) < sizeof($precbits)) {  // animation candidate
   if ($currgds < sizeof($gds)) {

     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else if (sizeof($gds) == 0)  {
     $gds[sizeof($gds)]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   } else if ($currgds < sizeof($gds)) {
     $gds[$currgds]=$gd;
     if (($currgds + 1) < sizeof($gds)) {
     $gd=$gds[$currgds + 1];
     } else {
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
     }
   } else {
     $gds[sizeof($gds) - 1]=$gd;
     $gd = imagecreatetruecolor($x, $y);
if (isset($_GET['positive']) || isset($_POST['positive']) || isthere(false,'positive') != '') {
$background = imagecreatetruecolor($x,$y); 
$wb = imagecolorallocatealpha($gd, 255, 255, 255, $reverseopacity); 
imagefill($gd,0,0,$wb);
}
   }
   $currgds++;
$xyarray=[];
}


}
} else if (!isset($_GET['circle']) && !isset($_POST['circle']) && isthere(false,'circle') == '') {
  if (isset($_GET['raster'])) {
  $pts=explode(":", urldecode($_GET['raster']));
  $lns=explode(";", $pts[1]);
  for ($ilns=0;$ilns<sizeof($lns);$ilns++) {
  $coos=explode(",", $lns[$ilns]);
  for ($icoos=0;$icoos<sizeof($coos);$icoos++) {
  if (strpos($coos[$icoos], ".") !== false) {  
  $red = imagecolorallocatealpha(gdback($gd), (255 - intval(substr($coos[$icoos],-3))), (255 - intval(substr($coos[$icoos],-3))), (255 - intval(substr($coos[$icoos],-3))), $reverseopacity); 
  }
  if (sizeof($coos) > 1) {
  if (($icoos + 1) < sizeof($coos)) {
  ourimagesetpixelline(gdback($gd), (floor($coos[$icoos]) % $width), ((floor($coos[$icoos]) - (floor($coos[$icoos]) % $width)) / $width), (floor($coos[$icoos + 1]) % $width), ((floor($coos[$icoos + 1]) - (floor($coos[$icoos + 1]) % $width)) / $width),$red);
  }
  } else {
  ourimagesetpixel(gdback($gd), (floor($coos[$icoos]) % $width), ((floor($coos[$icoos]) - (floor($coos[$icoos]) % $width)) / $width), $red);
  }
  }
  }
  } else if (isthere(false, 'raster') != "") { 
  $pts=explode(":", urldecode(isthere(false, 'raster')));
  $lns=explode(";", $pts[1]);
  for ($ilns=0;$ilns<sizeof($lns);$ilns++) {
  $coos=explode(",", $lns[$ilns]);
  for ($icoos=0;$icoos<sizeof($coos);$icoos++) {
  if (strpos($coos[$icoos], ".") !== false) {  
  $red = imagecolorallocatealpha(gdback($gd), (255 - intval(substr($coos[$icoos],-3))), (255 - intval(substr($coos[$icoos],-3))), (255 - intval(substr($coos[$icoos],-3))), $reverseopacity); 
  }
  if (sizeof($coos) > 1) {
  if (($icoos + 1) < sizeof($coos)) {
  ourimagesetpixelline(gdback($gd), (floor($coos[$icoos]) % $width), ((floor($coos[$icoos]) - (floor($coos[$icoos]) % $width)) / $width), (floor($coos[$icoos + 1]) % $width), ((floor($coos[$icoos + 1]) - (floor($coos[$icoos + 1]) % $width)) / $width),$red);
  }
  } else {
  ourimagesetpixel(gdback($gd), (floor($coos[$icoos]) % $width), ((floor($coos[$icoos]) - (floor($coos[$icoos]) % $width)) / $width), $red);
  }
  }
  }
  } else {
  for ($i = 0; $i < $howmany; $i++) {
  ourimagesetpixel(gdback($gd), round($x),round($y), $red);
  if (1 == 1) {
  $x = rand(0, $width);
  $y = rand(0, $height);
  $red = imagecolorallocatealpha(gdback($gd), rand(0, 255), rand(0, 255), rand(0, 255), $reverseopacity); 
  } else {
  $a = rand(0, 2);
  $x = ($x + $corners[$a]['x']) / 2;
  $y = ($y + $corners[$a]['y']) / 2;
  }
  }
}



}

if (sizeof($gds) > 0) {  // animated gif
  if (1 == 2) $gds[sizeof($gds)]=$gd;
  if (isset($_GET['rotate'])) {
  for ($ij=0; $ij<sizeof($gds); $ij++) {
  $gds[$ij]=rotate($gds[$ij], urldecode($_GET['rotate']));
  }
  } else if (isset($_POST['rotate']) || isthere(false,'rotate') != '') {
  for ($ij=0; $ij<sizeof($gds); $ij++) {
  $gds[$ij]=rotate($gds[$ij], urldecode(isthere(false,'rotate')));
  }
  }
  //$width = $new_width;
  //$height = $new_height;
  $gd=$gds[0];
} else if (isset($_GET['rotate'])) {
  $gd=rotate($gd, urldecode($_GET['rotate']));
  //$width = $new_width;
  //$height = $new_height;
} else if (isset($_POST['rotate']) || isthere(false,'rotate') != '') {
  $gd=rotate($gd, urldecode(isthere(false,'rotate')));
  //$width = $new_width;
  //$height = $new_height;
}

 
if (!isset($_GET['mode']) && !isset($_POST['mode']) && isthere(false,'mode') == '') {
if (sizeof($gds) == 0 && $width == $new_width && $height == $new_height) {
header('Content-Type: image/png');
imagepng($gd);
} else {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img>' . $endbody . '</body></html>';
}
} else { // thanks to https://stackoverflow.com/questions/8551754/convert-gd-output-to-base64 for ideas
if (isset($_GET['mode'])) {
if (strpos(strtolower(urldecode($_GET['mode'])),'image') !== false && strlen(urldecode($_GET['mode'])) == strlen('image')) {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img>' . $endbody . '</body></html>';
} else if (strpos(strtolower(urldecode($_GET['mode'])),'image') !== false && strlen(urldecode($_GET['mode'])) != strlen('image')) {
$idb = modeideas($gd,"parent.","getElementById('" . substr(urldecode($_GET['mode']),strlen('image')) . "').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('image')) . '").style.width="' . $width . 'px";   parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('image')) . '").style.height="' . $height . 'px";   parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('image')) . '").src="data:image/png;base64,' . $idb . '";  </scr' . "ipt></head><body>" . $endbody . "</body></html>";
} else if (strpos(strtolower(urldecode($_GET['mode'])),'img') !== false && strlen(urldecode($_GET['mode'])) == strlen('img')) {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img>' . $endbody . '</body></html>';
} else if (strpos(strtolower(urldecode($_GET['mode'])),'img') !== false && strlen(urldecode($_GET['mode'])) != strlen('img')) {
$idb = modeideas($gd,"parent.","getElementById('" . substr(urldecode($_GET['mode']),strlen('img')) . "').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('img')) . '").style.width="' . $width . 'px";   parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('img')) . '").style.height="' . $height . 'px";   parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('img')) . '").src="data:image/png;base64,' . $idb . '";  </scr' . "ipt></head><body>" . $endbody . "</body></html>";
} else if (strpos(strtolower(urldecode($_GET['mode'])),'div') !== false && strlen(urldecode($_GET['mode'])) == strlen('div')) {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><div id=dpthing class="dp0" style="width:' . $width . 'px;height:' . $height . 'px;"><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img></div>' . $endbody . '</body></html>';
} else if (strpos(strtolower(urldecode($_GET['mode'])),'div') !== false && strlen(urldecode($_GET['mode'])) != strlen('div')) {
$idb = modeideas($gd,"parent.","getElementById('" . substr(urldecode($_GET['mode']),strlen('div')) . "').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('div')) . '").style.width="' . $width . 'px";   parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('div')) . '").style.height="' . $height . 'px";  parent.document.getElementById("' . substr(urldecode($_GET['mode']),strlen('div')) . '").innerHTML="<img id=pthing class=p0 style=width:' . $width . "px;height:" . $height . "px; src='data:image/png;base64," . $idb . "'></img>" . '";  </scr' . "ipt></head><body>" . $endbody . "</body></html>";
} else if (strpos(strtolower(urldecode($_GET['mode'])),'canvas') !== false && strlen(urldecode($_GET['mode'])) == strlen('canvas')) {
$idb = modeideas($gd,"","title","onl(",")");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
$jsis=" var image=null, ctx=null, huh=null, canvas=null; function onl(nowmaybe) { canvas = document.getElementById('c'); \n"; // thanks to https://stackoverflow.com/questions/17090571/is-there-a-way-to-set-background-image-as-a-base64-encoded-image for ideas
$jsis.=" canvas.width = '" . $width . "';  \n"; 
$jsis.=" canvas.height = '" . $height . "';  \n"; 
$jsis.=" ctx = canvas.getContext('2d'); \n\n"; 
$jsis.=" image = new Image(); \n"; 
$jsis.=" image.width = '" . $width . "';  \n"; 
$jsis.=" image.height = '" . $height . "';  \n"; 
$jsis.=" image.onload = function() {  \n"; 
$jsis.="     ctx.drawImage(image, 0, 0, " . $width . ", " . $height . ", 0, 0, " . $width . ", " . $height . ");  \n"; 
$jsis.=" }; if (nowmaybe.length > 0) { image.src=nowmaybe; } return 'canvas'; } \n"; 
$jsis.=" function iis(inu) { if (inu != '') { image = new Image(); image.src = 'data:image/png;base64,' + inu;  } else { image.src = 'data:image/png;base64," . $idb . "'; } return 'canvas'; } image.src = 'data:image/png;base64," . $idb . "';   \n"; 
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> var xxx=""; ' . $jsis . '  </scr' . 'ipt></head><body onload="onl(xxx);  image.src = ' . "'data:image/png;base64," . $idb . "'; " . '"><canvas id=c width=' . $width . 'px height="' . $height . 'px"</canvas>' . $endbody . '</body></html>';
} else if (strpos(strtolower(urldecode($_GET['mode'])),'canvas') !== false && strlen(urldecode($_GET['mode'])) != strlen('canvas')) {
$idb = modeideas($gd,"","title","onl(",")");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
$jsis=" var image=null, ctx=null, huh=null, canvas=null;  function onl(nowmaybe) { canvas = parent.document.getElementById('" . substr(urldecode($_GET['mode']),strlen('canvas')) . "'); \n"; // thanks to https://stackoverflow.com/questions/17090571/is-there-a-way-to-set-background-image-as-a-base64-encoded-image for ideas
$jsis.=" canvas.width = '" . $width . "';  \n"; 
$jsis.=" canvas.height = '" . $height . "';  \n"; 
$jsis.=" ctx = canvas.getContext('2d'); \n\n"; 
$jsis.=" image = new Image(); \n"; 
$jsis.=" image.width = '" . $width . "';  \n"; 
$jsis.=" image.height = '" . $height . "';  \n"; 
$jsis.=" image.onload = function() {  \n"; 
$jsis.="     ctx.drawImage(image, 0, 0, " . $width . ", " . $height . ", 0, 0, " . $width . ", " . $height . ");  \n"; 
$jsis.=" }; if (nowmaybe.length > 0) { image.src=nowmaybe; } return 'canvas';  } \n"; 
$jsis.=" function iis(inu) { if (inu != '') { image = new Image(); image.src = 'data:image/png;base64,' + inu;  } else { image.src = 'data:image/png;base64," . $idb . "'; } return 'canvas';  } image.src = 'data:image/png;base64," . $idb . "';   \n"; 
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> var xxx="";  ' . $jsis . '  </scr' . 'ipt></head><body <body onload="onl(xxx);  image.src = "data:image/png;base64,' . $idb . '"; ' . "'></body></html>";
} else if (strpos(strtolower(urldecode($_GET['mode'])),'background') !== false && strlen(urldecode($_GET['mode'])) == strlen('background')) {
$idb = modeideas($gd,"","body.style.backgroundImage","\"URL(",")\"");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body style=' . "'" . 'background:URL("data:image/png;base64,' . $idb . '"); background-repeat:no-repeat;' . "'>" . $endbody . "</body></html>";
} else if (strpos(strtolower(urldecode($_GET['mode'])),'background') !== false && strlen(urldecode($_GET['mode'])) != strlen('background')) {
$idb = modeideas($gd,"parent.","getElementById('" . substr(urldecode($_GET['mode']),strlen('background')) . "').style.backgroundImage","\"URL(",")\"");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . "ipt type='text/javascript'> if (parent.document.getElementById('" . substr(urldecode($_GET['mode']),strlen('background')) . "')) { parent.document.getElementById('" . substr(urldecode($_GET['mode']),strlen('background')) . "').style.width='" . $width . "px';   parent.document.getElementById('" . substr(urldecode($_GET['mode']),strlen('background')) . "').style.height='" . $height . "px';   parent.document.getElementById('" . substr(urldecode($_GET['mode']),strlen('background')) . "').style.backgroundRepeat='no-repeat';     parent.document.getElementById('" . substr(urldecode($_GET['mode']),strlen('background')) . "').style.backgroundImage=" . "'" . 'URL("data:image/png;base64,' . $idb . '")' . "';   } else {  parent.document.body.style.width='" . $width . "px';   parent.document.body.style.height='" . $height . "px';    parent.body.style.backgroundImage=" . "'" . 'URL("data:image/png;base64,' . $idb . '")' . "'; parent.document.body.style.width='" . $width . "px';   parent.document.body.style.height='" . $height . "px';    parent.body.style.backgroundImage=" . "'" . 'URL("data:image/png;base64,' . $idb . '")' . "'; }   </scr" . "ipt></head><body>" . $endbody . "</body></html>";
} else { 
header('Content-Type: image/png');
imagepng($gd);
}


} else {
if (strpos(strtolower(urldecode(isthere(false,'mode'))),'image') !== false && strlen(urldecode(isthere(false,'mode'))) == strlen('image')) {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img></body></html>';
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'image') !== false && strlen(urldecode(isthere(false,'mode'))) != strlen('image')) {
$idb = modeideas($gd,"parent.","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('image')) . '").style.width="' . $width . 'px";   parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('image')) . '").style.height="' . $height . 'px";  parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('image')) . '").src="data:image/png;base64,' . $idb . '";  </scr' . "ipt></head><body></body></html>";
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'img') !== false && strlen(urldecode(isthere(false,'mode'))) == strlen('img')) {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img></body></html>';
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'img') !== false && strlen(urldecode(isthere(false,'mode'))) != strlen('img')) {
$idb = modeideas($gd,"parent.","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('img')) . '").style.width="' . $width . 'px";   parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('img')) . '").style.height="' . $height . 'px";  parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('img')) . '").src="data:image/png;base64,' . $idb . '";  </scr' . "ipt></head><body></body></html>";
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'div') !== false && strlen(urldecode(isthere(false,'mode'))) == strlen('div')) {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><div id=dpthing class="dp0" style="width:' . $width . 'px;height:' . $height . 'px;"><img id=pthing class=p0 style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img></div></body></html>';
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'div') !== false && strlen(urldecode(isthere(false,'mode'))) != strlen('div')) {
$idb = modeideas($gd,"parent.","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('div')) . '").style.width="' . $width . 'px";   parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('div')) . '").style.height="' . $height . 'px";  parent.document.getElementById("' . substr(urldecode(isthere(false,'mode')),strlen('div')) . '").innerHTML="<img id=pthing class=p0 style=width:' . $width . "px;height:" . $height . "px; src='data:image/png;base64," . $idb . "'></img>" . '";  </scr' . "ipt></head><body></body></html>";
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'canvas') !== false && strlen(urldecode(isthere(false,'mode'))) == strlen('canvas')) {
$idb = modeideas($gd,"","title","onl(",")");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
$jsis=" var image=null, ctx=null, huh=null, canvas=null;    function onl(nowmaybe) { canvas = document.getElementById('c'); \n"; // thanks to https://stackoverflow.com/questions/17090571/is-there-a-way-to-set-background-image-as-a-base64-encoded-image for ideas
$jsis.=" canvas.width = '" . $width . "';  \n"; 
$jsis.=" canvas.height = '" . $height . "';  \n"; 
$jsis.=" ctx = canvas.getContext('2d'); \n\n"; 
$jsis.=" image = new Image(); \n"; 
$jsis.=" image.width = '" . $width . "';  \n"; 
$jsis.=" image.height = '" . $height . "';  \n"; 
$jsis.=" image.onload = function() {  \n"; 
$jsis.="     ctx.drawImage(image, 0, 0, " . $width . ", " . $height . ", 0, 0, " . $width . ", " . $height . ");  \n"; 
$jsis.=" }; if (nowmaybe.length > 0) { image.src=nowmaybe; } return 'canvas';  } \n"; 
$jsis.=" function iis(inu) { if (inu != '') { image = new Image(); image.src = 'data:image/png;base64,' + inu;  } else { image.src = 'data:image/png;base64," . $idb . "'; } return 'canvas';  } image.src = 'data:image/png;base64," . $idb . "';   \n"; 
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> var xxx="";  ' . $jsis . '  </scr' . 'ipt></head><body onload="onl(xxx);  image.src = ' . "'data:image/png;base64," . $idb . "'; " . '"><canvas id=c width=' . $width . 'px height="' . $height . 'px"</canvas></body></html>';
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'canvas') !== false && strlen(urldecode(isthere(false,'mode'))) != strlen('canvas')) {
$idb = modeideas($gd,"","title","onl(",")");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
$jsis=" var image=null, ctx=null, huh=null, canvas=null;    function onl(nowmaybe) { canvas = parent.document.getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('canvas')) . "'); \n"; // thanks to https://stackoverflow.com/questions/17090571/is-there-a-way-to-set-background-image-as-a-base64-encoded-image for ideas
$jsis.=" canvas.width = '" . $width . "';  \n"; 
$jsis.=" canvas.height = '" . $height . "';  \n"; 
$jsis.=" ctx = canvas.getContext('2d'); \n\n"; 
$jsis.=" image = new Image(); \n"; 
$jsis.=" image.width = '" . $width . "';  \n"; 
$jsis.=" image.height = '" . $height . "';  \n"; 
$jsis.=" image.onload = function() {  \n"; 
$jsis.="     ctx.drawImage(image, 0, 0, " . $width . ", " . $height . ", 0, 0, " . $width . ", " . $height . ");  \n"; 
$jsis.=" }; if (nowmaybe.length > 0) { image.src=nowmaybe; } return 'canvas';  } \n"; 
$jsis.=" function iis(inu) { if (inu != '') { image = new Image(); image.src = 'data:image/png;base64,' + inu;  } else { image.src = 'data:image/png;base64," . $idb . "'; } return 'canvas';  }  \n"; 
echo '<!doctype html><html><head><scr' . 'ipt type="text/javascript"> var xxx="";  ' . $jsis . '  </scr' . 'ipt></head><body onload="onl(xxx);  image.src = ' . "'data:image/png;base64," . $idb . "'; " . '"></body></html>';
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'background') !== false && strlen(urldecode(isthere(false,'mode'))) == strlen('background')) {
$idb = modeideas($gd,"","body.style.backgroundImage","\"URL(",")\"");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body style=' . "'" . 'background:URL("data:image/png;base64,' . $idb . '"); background-repeat:no-repeat;' . "'>" . $endbody . "</body></html>";
} else if (strpos(strtolower(urldecode(isthere(false,'mode'))),'background') !== false && strlen(urldecode(isthere(false,'mode'))) != strlen('background')) {
$idb = modeideas($gd,"parent.","getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('background')) . "').style.backgroundImage","\"URL(",")\"");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "';  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><head><scr' . "ipt type='text/javascript'> if (parent.document.getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('background')) . "')) { parent.document.getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('background')) . "').style.width='" . $width . "px';   parent.document.getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('background')) . "').style.height='" . $height . "px';   parent.document.getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('background')) . "').style.backgroundRepeat='no-repeat';   parent.document.getElementById('" . substr(urldecode(isthere(false,'mode')),strlen('background')) . "').style.backgroundImage=" . "'" . 'URL("data:image/png;base64,' . $idb . '")' . "';   } else {  parent.document.body.style.width='" . $width . "px';   parent.document.body.style.height='" . $height . "px';    parent.body.style.backgroundImage=" . "'" . 'URL("data:image/png;base64,' . $idb . '")' . "'; parent.document.body.style.width='" . $width . "px';   parent.document.body.style.height='" . $height . "px';    parent.body.style.backgroundImage=" . "'" . 'URL("data:image/png;base64,' . $idb . '")' . "'; }   </scr" . "ipt></head><body>" . $endbody . "</body></html>";
} else { 
if (sizeof($gds) == 0 && $width == $new_width && $height == $new_height) {
header('Content-Type: image/png');
imagepng($gd);
} else {
$idb = modeideas($gd,"","getElementById('pthing').src","","");
if ($width != $new_width || $height != $new_height) {
  $endbody=str_replace(" var currgds=0;", " if (parent.document.getElementById('toppixellate')) {  parent.document.getElementById('pwidth').value='" . $new_width . "';  parent.document.getElementById('pheight').value='" . $new_height . $spacechar . "'; parent.document.getElementById('toppixellate').style.width='" . $new_width . "px'; parent.document.getElementById('toppixellate').style.height='" . $new_height . "px';  parent.document.getElementById('toppixellate').width='" . $new_width . "px'; parent.document.getElementById('toppixellate').height='" . $new_height . "px'; } var currgds=0;", $endbody);
} 
$width == $new_width;
$height == $new_height;
echo '<!doctype html><html><body><img id=pthing class="p0" style="width:' . $width . 'px;height:' . $height . 'px;" src="data:image/png;base64,' . $idb . '"></img>' . $endbody . '</body></html>';
}
}
}
}

?>
