From 202a7876ec508fd70385497c1508b33aeb367c67 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 24 Feb 2017 16:40:56 -0800 Subject: [PATCH] nicer photo uploading experience --- lib/helpers.php | 32 ++--- public/css/style.css | 23 ++++ views/layout.php | 4 + views/new-post.php | 308 ++++++++++++++++++++++++++++++++----------- 4 files changed, 278 insertions(+), 89 deletions(-) diff --git a/lib/helpers.php b/lib/helpers.php index d932e67..b7ae78d 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -363,21 +363,23 @@ function validate_photo(&$file) { // Only does anything if the exif library is loaded, otherwise is a noop. function correct_photo_rotation($filename) { if(class_exists('IMagick')) { - $image = new IMagick($filename); - $orientation = $image->getImageOrientation(); - switch($orientation) { - case IMagick::ORIENTATION_BOTTOMRIGHT: - $image->rotateImage(new ImagickPixel('#00000000'), 180); - break; - case IMagick::ORIENTATION_RIGHTTOP: - $image->rotateImage(new ImagickPixel('#00000000'), 90); - break; - case IMagick::ORIENTATION_LEFTBOTTOM: - $image->rotateImage(new ImagickPixel('#00000000'), -90); - break; - } - $image->setImageOrientation(IMagick::ORIENTATION_TOPLEFT); - $image->writeImage($filename); + try { + $image = new IMagick($filename); + $orientation = $image->getImageOrientation(); + switch($orientation) { + case IMagick::ORIENTATION_BOTTOMRIGHT: + $image->rotateImage(new ImagickPixel('#00000000'), 180); + break; + case IMagick::ORIENTATION_RIGHTTOP: + $image->rotateImage(new ImagickPixel('#00000000'), 90); + break; + case IMagick::ORIENTATION_LEFTBOTTOM: + $image->rotateImage(new ImagickPixel('#00000000'), -90); + break; + } + $image->setImageOrientation(IMagick::ORIENTATION_TOPLEFT); + $image->writeImage($filename); + } catch(Exception $e){} } } diff --git a/public/css/style.css b/public/css/style.css index 7984fe5..4a2acff 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -203,6 +203,29 @@ body { } +/** + * nicer file upload + */ +.btn-file { + position: relative; + overflow: hidden; +} +.btn-file input[type=file] { + position: absolute; + top: 0; + right: 0; + min-width: 100%; + min-height: 100%; + font-size: 100px; + text-align: right; + filter: alpha(opacity=0); + opacity: 0; + outline: none; + background: white; + cursor: inherit; + display: block; +} + .glyphicon-spin { -webkit-animation: spin 1000ms infinite linear; diff --git a/views/layout.php b/views/layout.php index 4d5e5c0..6f27e92 100644 --- a/views/layout.php +++ b/views/layout.php @@ -22,9 +22,13 @@ + + + + diff --git a/views/new-post.php b/views/new-post.php index e14c38f..1e57837 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -41,22 +41,11 @@ - - -