Allow clicking through to full quality images
[pics.git] / upload.php
index 883fa51..456cde7 100644 (file)
@@ -22,12 +22,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
       die('Upload error');
     }
     $size = $images['size'][$i];
-    // strip EXIF
+
+    // imagemagick manip code
     $img = new Imagick($tmp_file);
-    // keep ICC for quality
+    // no compression
+    $img->setImageCompressionQuality(100);
     $profiles = $img->getImageProfiles("icc", true);
+    $exif_orientation = $img->getImageOrientation();
+
+    // STRIP EXIF DATA
     $img->stripImage();
+
+    // REAPPLY EXIF DATA
+    if($exif_orientation === imagick::ORIENTATION_BOTTOMRIGHT) {
+      $img->rotateImage("#000", 180);
+    } elseif ($exif_orientation === imagick::ORIENTATION_RIGHTTOP) {
+      $img->rotateImage("#000", 90);
+    } elseif ($exif_orientation === imagick::ORIENTATION_LEFTBOTTOM) {
+      $img->rotateImage("#000", -90);
+    }
+    $img->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
     if(!empty($profiles)) {
+      // keep ICC for quality
       $img->profileImage('icc', $profiles['icc']);
     }
 
@@ -47,6 +63,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   $post_stmt->bindValue(':id', $post_id);
   $post_stmt->bindValue(':user', $user);
   $post_stmt->bindValue(':time', $post_time);
+
+  $comment_stmt = $db->prepare('INSERT into comments VALUES (:id, :post_id, :body)');
+  $comment_stmt->bindValue(':id', uuid_v4());
+  $comment_stmt->bindValue(':post_id', $post_id);
+  $comment_stmt->bindValue(':body', $_POST['comment'] ?? '');
+  $comment_stmt->execute();
   $post_stmt->execute();
 
   $db->exec('COMMIT');
@@ -54,7 +76,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
 echo '
   <html>
     <body>
-      <form enctype="multipart/form-data" method="POST" action="upload.php">
+      <form enctype="multipart/form-data" method="POST" action="upload">
        <label>Pick Images:<input type="file" id="upload" name="image[]" multiple>
         </input></label>
         <br/>