<?php
// image_dimensions.php
// RJM Programming
// October, 2017

set_time_limit(120);

$imagespec="";
$ximage="";
$topbit="<!doctype html><html><head><title>Image Dimensions Table - RJM Programming - October, 2017</title></head><body style=background-color:yellow;><h1>Image Dimensions</h1><h3>RJM Programming - October, 2017</h3><h4>Thanks to <a target=_blank title='ImageMagick' href='https://www.imagemagick.org'>ImageMagick</a></h4><form target='_self' id='myform' action='./image_dimensions.php' method='POST'>";
$prefix="";

if (isset($_GET['imagespec'])) {
  $ximage=urldecode($_GET['imagespec']);
  $imagespec = str_replace("//www.rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("//rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("http://www.rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("http://rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("https://www.rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("https://rjmprogramming.com.au/","/home/rjmprogr/public_html/",urldecode($_GET['imagespec'])))))));
} else if (isset($_POST['imagespec'])) {
  $ximage=urldecode($_POST['imagespec']);
  $imagespec = str_replace("//www.rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("//rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("http://www.rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("http://rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("https://www.rjmprogramming.com.au/","/home/rjmprogr/public_html/",str_replace("https://rjmprogramming.com.au/","/home/rjmprogr/public_html/",urldecode($_POST['imagespec'])))))));
} else if (1 == 2 && file_exists("/Applications/MAMP/htdocs/clouds.jpg")) {
  $imagespec = "/Applications/MAMP/htdocs/clouds.jpg";
} else {
  $ximage="http://www.rjmprogramming.com.au/fillThisIn*YouGetIt*.*g*";
}

$topbit.="<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image URL Specification: <input name='imagespec' id='image' type='text' value='" . str_replace("/home/rjmprogr/public_html/","http://www.rjmprogramming.com.au/",str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",$ximage)) . "' style='width:40%;'></input>&nbsp;&nbsp;<input id='isub' type='submit' value='Image Information'></input><br><br><table style=width:100%; border=20><tbody><tr><th>Image Name</th><th>Image Type</th><th><input type=submit name=width id=width value=Width+></input><input type=submit name=widthminus id=widthminus value=-></input> x <input type=submit name=height id=height value=Height+></input><input type=submit name=heightminus id=heightminus value=-></input></th><th>More</th><th>Image Bit Mode</th><th>Colour Space</th><th>Size</th><th></th><th></th></tr>";
if ($imagespec != "") {
    $ximage=$imagespec;
    //if (strpos($_SERVER['SERVER_NAME'], "rjmprogramming.com.au") !== false) {
    if (isset($_POST['widthminus'])) {
    exec($prefix . "identify " . $imagespec . " | sed '/ [1-9][0-9]*c /s// /g' | awk -F'[' '{ b=$1; gsub(\" \",\"@\",b); c=$0; gsub($1, b, c); print c; }' | awk -F' ' '{ c=substr($0,(1 + length($1))); b=$1; gsub(\" \",\"!@!\",b); print b \">\" b c; }' | sed '/ /s//\<\/img\>\<\/a\> /' | sed '/\[[1-9][0-9]*\]/s///g' | sed '/^/s//!/g' | sed '/$/s//`/g' | sort -k3 -n -t' ' > /tmp/pnginfo.txt");
    } else if (isset($_POST['width'])) {
    exec($prefix . "identify " . $imagespec . " | sed '/ [1-9][0-9]*c /s// /g' | awk -F'[' '{ b=$1; gsub(\" \",\"@\",b); c=$0; gsub($1, b, c); print c; }' | awk -F' ' '{ c=substr($0,(1 + length($1))); b=$1; gsub(\" \",\"!@!\",b); print b \">\" b c; }' | sed '/ /s//\<\/img\>\<\/a\> /' | sed '/\[[1-9][0-9]*\]/s///g' | sed '/^/s//!/g' | sed '/$/s//`/g' | sort -k3 -n -r -t' ' > /tmp/pnginfo.txt");
    } else if (isset($_POST['heightminus'])) {
    exec($prefix . "identify " . $imagespec . " | sed '/ [1-9][0-9]*c /s// /g' | awk -F'[' '{ b=$1; gsub(\" \",\"@\",b); c=$0; gsub($1, b, c); print c; }' | awk -F' ' '{ c=substr($0,(1 + length($1))); b=$1; gsub(\" \",\"!@!\",b); gsub(\"x\",\" 00\",c); b=$1; gsub(\" \",\"!@!\",b); print b \">\" b c; }' | sed '/ /s//\<\/img\>\<\/a\> /' | sed '/\[[1-9][0-9]*\]/s///g' | sed '/^/s//!/g' | sed '/$/s//`/g' | sort -k4 -n -t' ' | sed '/ 00/s//x/g' | sed '/#/s//x/g' > /tmp/pnginfo.txt");
    } else if (isset($_POST['height'])) {
    exec($prefix . "identify " . $imagespec . " | sed '/ [1-9][0-9]*c /s// /g' | awk -F'[' '{ b=$1; gsub(\" \",\"@\",b); c=$0; gsub($1, b, c); print c; }' | awk -F' ' '{ c=substr($0,(1 + length($1))); b=$1; gsub(\" \",\"!@!\",b); gsub(\"x\",\" 00\",c); b=$1; gsub(\" \",\"!@!\",b); print b \">\" b c; }' | sed '/ /s//\<\/img\>\<\/a\> /' | sed '/\[[1-9][0-9]*\]/s///g' | sed '/^/s//!/g' | sed '/$/s//`/g' | sort -k4 -n -r -t' ' | sed '/ 00/s//x/g' | sed '/#/s//x/g' > /tmp/pnginfo.txt");
    } else {
    exec($prefix . "identify " . $imagespec . " | sed '/ [1-9][0-9]*c /s// /g' | awk -F'[' '{ b=$1; gsub(\" \",\"@\",b); c=$0; gsub($1, b, c); print c; }' | awk -F' ' '{ c=substr($0,(1 + length($1))); b=$1; gsub(\" \",\"!@!\",b); print b \">\" b c; }' | sed '/ /s//\<\/img\>\<\/a\> /' | sed '/\[[1-9][0-9]*\]/s///g' | sed '/^/s//!/g' | sed '/$/s//`/g' > /tmp/pnginfo.txt");
    }
    $topbit.=str_replace("@"," ",str_replace("imgsrc=","img style=width:45px; src=",str_replace("!","<tr><td><a style=cursor:pointer;text-decoration:underline; title=Image onclick='location.href=this.innerHTML.split(\"</img>\")[0].split(\">\")[eval(-1 + this.innerHTML.split(\"</img>\")[0].split(\">\").length)];'><imgsrc=",str_replace(" ","</td><td>",str_replace("`","</td></tr>",  str_replace("/home/rjmprogr/public_html/","http://www.rjmprogramming.com.au/",   str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",  @file_get_contents("/tmp/pnginfo.txt"))))))));
    //} else {
    //echo '/opt/local/bin/identify ' . $imagespec . ' > /tmp/pnginfo.txt';
    //exec("/opt/local/bin/identify " . $imagespec . " | awk -F' ' '{ print $1 \">\" $0;  }' | sed '/ /s//\<\/img\>\<\/a\> /' | sed '/\[[1-9][0-9]*\]/s///g' | sed '/^/s//!/g' | sed '/$/s//`/g' > /tmp/pnginfo.txt");
    //$topbit.=str_replace("imgsrc=","img style=width:45px; src=",str_replace("!","<tr><td><a style=cursor:pointer;text-decoration:underline; title=Image onclick='location.href=this.innerHTML.split(\"</img>\")[0].split(\">\")[eval(-1 + this.innerHTML.split(\"</img>\")[0].split(\">\").length)];'><imgsrc=",str_replace(" ","</td><td>",str_replace("`","</td></tr>",   str_replace("/home/rjmprogr/public_html/","http://www.rjmprogramming.com.au/",   str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",       @file_get_contents("/tmp/pnginfo.txt")))))));
    //echo file_get_contents("/tmp/pnginfo.txt");
    //}
}


echo $topbit . "</tbody></table></form></body></html>";

?>