46 lines
988 B
PHP
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();
|
|
|
|
}
|
|
|
|
?>
|