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 @@