From 45d10dabf9aefbc62042a741d1eadd8bc4c2eeae Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sun, 9 Apr 2023 16:56:05 +0100 Subject: [PATCH] add toggle for web p and added quality config --- upload.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/upload.php b/upload.php index 76757e2..0e9627a 100644 --- a/upload.php +++ b/upload.php @@ -9,6 +9,8 @@ header('Content-type:application/json;charset=utf-8'); // Set the content type t $tokens = array("set me"); // Your secret keys $uploadDir = "./"; // The upload directory $useRandomFileNames = false; // Use random file names instead of the original file name +$shouldConvertToWebp = true; // Should the script convert images to webp? +$webpQuality = 90; // The quality of the webp image (0-100) $fileNameLength = 8; // The length of the random file name $webpThreadhold = 1048576; // 1MB - The minimum file size for converting to webp (in bytes) @@ -77,10 +79,10 @@ try { } // Convert the image to webp if applicable - if (in_array($fileType, array("png", "jpeg", "jpg")) && $_FILES["sharex"]["size"] > $webpThreadhold) { + if (in_array($fileType, array("png", "jpeg", "jpg")) && $_FILES["sharex"]["size"] > $webpThreadhold && $shouldConvertToWebp) { $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"])); $webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp"; - imagewebp($image, $webp_file, 90); // Convert the image and save it + imagewebp($image, $webp_file, $webpQuality); // Convert the image and save it imagedestroy($image); // Free up memory $finalName = $webp_file; $shouldSave = false;