<?php
// read_exif_off_image_rotate.php
// RJM Programming
// August, 2016
// Thanks to http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data

$nform="<br><form action='./read_exif_off_image_rotate.php' method='POST'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image URL: <input name='image' id='image' type='text' value=''></input>&nbsp;&nbsp;<input type='submit' value='Exif Information'></input></form>";
$rotbit="";

$htmlis="";
$indiv="";

if (isset($_GET['image'])) {
  $image = urldecode($_GET['image']);
} else if (isset($_POST['image'])) {
  $image = urldecode($_POST['image']);
} else {
  $image = "/Applications/MAMP/htdocs/clouds.jpg";
}

$types = array(
1 => "GIF",
2 => "JPEG",
3 => "PNG",
4 => "SWF",
5 => "PSD",
6 => "BMP",
7 => "TIFF",
8 => "TIFF"
);

$imagetype = exif_imagetype($image);

if (array_key_exists($imagetype, $types)) {
 $htmlis="<!doctype html><html><head><title>Exif for " . $image . "</title></head><body style='background-color:pink;'><h1>Exif for " . $image . "</h1><h3>RJM Programming - August, 2016</h3><h4>Thanks to <a target=_blank title=Useful href=http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data>http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data</a></h4><div style='background-color:yellow; background: url(" . str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",$image) . "); norepeat; '><br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image type of " . $image . " is: " . $types[$imagetype];
 $exif = exif_read_data($image, 0, true);
 foreach ($exif as $key => $section) {
  foreach ($section as $name => $val) {
   $indiv.="<br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$key.$name: $val";
   if (($key.$name) == "IFD0Orientation") {
     if (str_replace(" ","","$val") == "8") {
       //$htmlis="<!doctype html><html><head><title>Exif for " . $image . "</title></head><body style='background-color:yellow; background: url(" . str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",$image) . "); norepeat; " . $rotbit . "'><h1>Exif for " . $image . "</h1><h3>RJM Programming - August, 2016</h3><h4>Thanks to <a target=_blank title=Useful href=http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data>http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data</a></h4><div><br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image type of " . $image . " is: " . $types[$imagetype];
       $htmlis=str_replace("; norepeat; ", "; opacity:0.6; norepeat; -webkit-transform: rotate(270deg); -moz-transform: rotate(270deg); -ms-transform: rotate(270deg); -o-transform: rotate(270deg); transform: rotate(270deg); ", $htmlis);
     } else if (str_replace(" ","","$val") == "6") {
       //$htmlis="<!doctype html><html><head><title>Exif for " . $image . "</title></head><body style='background-color:yellow; background: url(" . str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",$image) . "); norepeat; " . $rotbit . "'><h1>Exif for " . $image . "</h1><h3>RJM Programming - August, 2016</h3><h4>Thanks to <a target=_blank title=Useful href=http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data>http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data</a></h4><div><br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image type of " . $image . " is: " . $types[$imagetype];
       $htmlis=str_replace("; norepeat; ", "; opacity:0.6;  norepeat; -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -ms-transform: rotate(90deg); -o-transform: rotate(90deg); transform: rotate(90deg); ", $htmlis);
     } else if (str_replace(" ","","$val") == "3") {
       //$htmlis="<!doctype html><html><head><title>Exif for " . $image . "</title></head><body style='background-color:yellow; background: url(" . str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",$image) . "); norepeat; " . $rotbit . "'><h1>Exif for " . $image . "</h1><h3>RJM Programming - August, 2016</h3><h4>Thanks to <a target=_blank title=Useful href=http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data>http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data</a></h4><div><br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image type of " . $image . " is: " . $types[$imagetype];
       $htmlis=str_replace("; norepeat; ", "; opacity:0.6;  norepeat; -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); -o-transform: rotate(180deg); transform: rotate(180deg); ", $htmlis);
     }
   }
  }
 }
 if (str_replace("transXXXform:","",$htmlis) != $htmlis) {
   echo str_replace("</h4><div", "</h4>" . $indiv . "<div", $htmlis) . "</div>" . $nform . "</body></html>";
 } else {
   echo $htmlis . $indiv . "</div>" . $nform . "</body></html>";
 }
} else {
 echo "<br>" . "Not a valid image type for " . $image . " or Exif functionality not enabled." . $nform;
}
?>