thumbnail.php generate thumbnails on demand

This commit is contained in:
j3d1 2019-12-05 18:52:48 +01:00
parent d0458cd23b
commit d321093d0f
2 changed files with 27 additions and 1 deletions

2
.gitignore vendored
View file

@ -4,6 +4,8 @@ Homestead.json
Homestead.yaml
.env
/public/docs
/public/staticimages
/public/thumbnails
/resources/docs
composer.lock

View file

@ -1,3 +1,27 @@
<?php
echo "TODO: create thumbnail for ".$_GET["id"]." here";
#echo "TODO: create thumbnail for ".$_GET["id"]." here";
$width = 100;
$height = 100;
$quality = 90;
$thumb = getcwd() . $_GET["id"];
$img = str_replace("thumbnails", "staticimages", $thumb);
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($thumb, $imagick) === false) {
throw new Exception("Could not put contents.");
}
return true;
} else {
throw new Exception("No valid image provided with {$img}.");
}
?>