From fa57cb3fd4607d37b66abe4d8cd3de254f47126f Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Sun, 24 Feb 2019 11:52:15 +0100 Subject: [PATCH] add thumbnails --- ajax.php | 22 ++++++++++++++++++++++ templates/found_item.php | 3 +++ templates/lost_item.php | 2 +- templates/sidebar.php | 10 ++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ajax.php b/ajax.php index 3409b1a..bcea2c0 100644 --- a/ajax.php +++ b/ajax.php @@ -13,6 +13,26 @@ function hasval($var){ return isset($var) && !empty($var); } +function makethumb($hash, $width=100, $height=100, $quality = 90) +{ + $img = getcwd()."/upload/".$hash; + if (is_file($img)) { + $imagick = new Imagick($img); + $imagick->setImageFormat('jpeg'); + $imagick->setImageCompression(Imagick::COMPRESSION_JPEG); + $imagick->setImageCompressionQuality($quality); + $imagick->cropThumbnailImage($width, $height); + $imagick->setImagePage(0, 0, 0, 0); + if (file_put_contents(getcwd()."/thumb/" . $hash, $imagick) === false) { + throw new Exception("Could not put contents."); + } + return true; + } + else { + throw new Exception("No valid image provided with {$img}."); + } +} + $successmsg = "added one item"; switch($_GET["action"]) { @@ -134,6 +154,7 @@ switch($_GET["action"]) { if (!$stmt->execute()) { $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } + makethumb($hash); $successmsg = "one item edited"; }else{ @@ -177,6 +198,7 @@ switch($_GET["action"]) { if (!$stmt->execute()) { $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } + makethumb($hash); $successmsg = "upload ok"; }else{ $errormsg = "upload failed"; diff --git a/templates/found_item.php b/templates/found_item.php index 662ad04..2e4450a 100644 --- a/templates/found_item.php +++ b/templates/found_item.php @@ -49,6 +49,9 @@
+
+ +
diff --git a/templates/lost_item.php b/templates/lost_item.php index d4153fd..5b950c5 100644 --- a/templates/lost_item.php +++ b/templates/lost_item.php @@ -82,7 +82,7 @@ - "> + ">
diff --git a/templates/sidebar.php b/templates/sidebar.php index 48bb7a0..14449df 100644 --- a/templates/sidebar.php +++ b/templates/sidebar.php @@ -100,7 +100,7 @@ Tables - + + +