Compare commits
No commits in common. "5799511916c175179336cfea6ed344a47875f0a6" and "4ebb8fafe224f79a1fae1ddb8f0e87251796e0b3" have entirely different histories.
5799511916
...
4ebb8fafe2
@ -3,7 +3,7 @@ FROM ubuntu:23.04
|
|||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN apt update
|
RUN apt update
|
||||||
RUN DEBIAN_FRONTEND=noninteractive \
|
RUN DEBIAN_FRONTEND=noninteractive \
|
||||||
apt install nginx php8.1 php8.1-fpm php8.1-gd php8.1-imagick -y
|
apt install nginx php8.1 php8.1-fpm php8.1-gd -y
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
RUN apt clean
|
RUN apt clean
|
||||||
|
31
upload.php
31
upload.php
@ -136,28 +136,15 @@ try {
|
|||||||
|
|
||||||
$needsToBeSaved = true; // Whether the file needs to be saved
|
$needsToBeSaved = true; // Whether the file needs to be saved
|
||||||
|
|
||||||
// Check the file type and size
|
if ($shouldConvertToWebp) { // Convert the image to webp if applicable
|
||||||
if ($shouldConvertToWebp && in_array($fileType, ["png", "jpeg", "jpg"]) && $_FILES["sharex"]["size"] > $webpThreadhold) {
|
if (in_array($fileType, array("png", "jpeg", "jpg")) && $_FILES["sharex"]["size"] > $webpThreadhold) {
|
||||||
// Create an Imagick object from the uploaded file
|
$image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"]));
|
||||||
$image = new Imagick($_FILES["sharex"]["tmp_name"]);
|
$webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp";
|
||||||
|
imagewebp($image, $webp_file, $webpQuality); // Convert the image and save it
|
||||||
// Convert the image to WebP
|
imagedestroy($image); // Free up memory
|
||||||
$image->setImageFormat("webp");
|
$finalName = $webp_file;
|
||||||
$image->setImageCompressionQuality($webpQuality);
|
$needsToBeSaved = false;
|
||||||
|
}
|
||||||
// Set the output filename
|
|
||||||
$webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp";
|
|
||||||
|
|
||||||
// Save the converted image
|
|
||||||
$image->writeImage($webp_file);
|
|
||||||
|
|
||||||
// Free up memory
|
|
||||||
$image->clear();
|
|
||||||
$image->destroy();
|
|
||||||
|
|
||||||
// Update the final filename
|
|
||||||
$finalName = $webp_file;
|
|
||||||
$needsToBeSaved = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($needsToBeSaved) { // Save the file if it has not been saved yet
|
if ($needsToBeSaved) { // Save the file if it has not been saved yet
|
||||||
|
Loading…
Reference in New Issue
Block a user