webApp/thumbnail.php
toto 0f2f5172ac Improve image thumbnail
And auto download apk for android
2022-02-16 16:32:29 +01:00

46 lines
988 B
PHP

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$root = $_SERVER["DOCUMENT_ROOT"];
$directory = "/uploads/";
if(isset($_GET["file"])) {
$file = $root.urldecode($_GET["file"]);
$size = isset($_GET["size"]) ? $_GET["size"] : 100;
if(file_exists($file)) {
echo getthumbnail($file, $size);
exit();
}
else {
header("HTTP/1.1 400 File not Found");
echo $file." not Found";
exit();
}
}
function getthumbnail(string $file, int $size)
{
list($width, $height) = getimagesize($file);
// Create an Imagick object
$imagick = new Imagick($file);
// Function to set the background color
$imagick->setbackgroundcolor('rgb(0, 0, 0)');
// Use thumbnailImage function
$imagick->thumbnailImage($width*$size/$height, $size, true, true);
header("Content-Type: image/jpg");
// Display the output image
echo $imagick->getImageBlob();
}
?>