Improve image thumbnail
And auto download apk for android
This commit is contained in:
46
thumbnail.php
Normal file
46
thumbnail.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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();
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user