c3lf-system-3/public/thumbnail.php
2020-01-18 00:39:45 +01:00

41 lines
1.1 KiB
PHP

<?php
function log_error(string $message){
if(!file_exists("../logs"))
mkdir("../logs");
file_put_contents('../logs/php_errors.log', $message.PHP_EOL , FILE_APPEND | LOCK_EX);
}
$width = 200;
$height = 200;
$quality = 90;
$thumb = getcwd() . $_GET["id"];
$img = str_replace("thumbnails", "staticimages", $thumb);
if (is_file($img)) {
try {
if(!file_exists("thumbnails"))
mkdir("thumbnails");
$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) {
log_error("Could not put contents.");
}
}catch(Exception $exception){
log_error($exception);
$imagick = file_get_contents($img);
}
header("Content-type: image/jpeg");
echo $imagick;
exit;
} else {
log_error("No valid image provided with {$img}.");
}
?>