diff --git a/upload.php b/upload.php index 6361f8d..83c017a 100644 --- a/upload.php +++ b/upload.php @@ -1,7 +1,6 @@ $webpThreadhold && $shouldConvertToWebp) { - $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"])); - $webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp"; - imagewebp($image, $webp_file, $webpQuality); // Convert the image and save it - imagedestroy($image); // Free up memory - $finalName = $webp_file; - $saved = true; + if ($shouldConvertToWebp) { // Convert the image to webp if applicable + if (in_array($fileType, array("png", "jpeg", "jpg")) && $_FILES["sharex"]["size"] > $webpThreadhold) { + $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"])); + $webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp"; + imagewebp($image, $webp_file, $webpQuality); // Convert the image and save it + imagedestroy($image); // Free up memory + $finalName = $webp_file; + $needsToBeSaved = false; + } } - if (!$saved) { // If the file wasn't saved (e.g. webp conversion) + if ($needsToBeSaved) { // Save the file if it has not been saved yet // Move the file to the uploads folder $success = move_uploaded_file($_FILES["sharex"]["tmp_name"], $uploadDir . $finalName); if (!$success) {