add thumbnails

This commit is contained in:
/jedi/ 2019-02-24 11:52:15 +01:00
parent d4c22b8742
commit fa57cb3fd4
4 changed files with 34 additions and 3 deletions

View file

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