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); 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"; $successmsg = "added one item";
switch($_GET["action"]) { switch($_GET["action"]) {
@ -134,6 +154,7 @@ switch($_GET["action"]) {
if (!$stmt->execute()) { if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
} }
makethumb($hash);
$successmsg = "one item edited"; $successmsg = "one item edited";
}else{ }else{
@ -177,6 +198,7 @@ switch($_GET["action"]) {
if (!$stmt->execute()) { if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
} }
makethumb($hash);
$successmsg = "upload ok"; $successmsg = "upload ok";
}else{ }else{
$errormsg = "upload failed"; $errormsg = "upload failed";

View file

@ -49,6 +49,9 @@
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" placeholder="WAS" name="was" autocomplete="off"> <input type="text" class="form-control" placeholder="WAS" name="was" autocomplete="off">
</div> </div>
<div class="form-group">
<input type="text" class="form-control" placeholder="KISTE" name="container" autocomplete="off">
</div>
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">

View file

@ -82,7 +82,7 @@
<td><?php echo $item["was"]; ?></td> <td><?php echo $item["was"]; ?></td>
<td><?php echo $item["wann"]; ?></td> <td><?php echo $item["wann"]; ?></td>
<td><?php echo $item["wo"]; ?></td> <td><?php echo $item["wo"]; ?></td>
<td><img style="height: 48px;" src="/upload/<?php echo $item["hash"]; ?>"></td> <td><img style="height: 48px;" src="/thumb/<?php echo $item["hash"]; ?>"></td>
<td> <td>
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary"><i class="fas fa-fw fa-check-circle"></i></button> <button type="button" class="btn btn-outline-secondary"><i class="fas fa-fw fa-check-circle"></i></button>

View file

@ -100,7 +100,7 @@
<a class="nav-link" href="../tables.html"> <a class="nav-link" href="../tables.html">
<i class="fas fa-fw fa-table"></i> <i class="fas fa-fw fa-table"></i>
<span>Tables</span></a> <span>Tables</span></a>
</li--> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/request/"> <a class="nav-link" href="/request/">
<i class="fas fa-fw fa-comments"></i> <i class="fas fa-fw fa-comments"></i>
@ -112,5 +112,11 @@
<i class="fas fa-fw fa-plus"></i> <i class="fas fa-fw fa-plus"></i>
<span>Item</span> <span>Item</span>
</a> </a>
</li> </li-->
<li class="nav-item">
<a class="nav-link" href="/table/">
<i class="fas fa-fw fa-archive"></i>
<span>Table</span>
</a>
</li>
</ul> </ul>