From 79e91e329654943f31e3059955c711ae1eafcc54 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Mon, 11 Sep 2023 17:10:52 +0200 Subject: [PATCH] Support webp format (#1785) * consider webP as an input and output format, meaning a derivative from webp is still a webp --- action.php | 1 + admin/include/functions_upload.inc.php | 4 ++++ admin/include/image.class.php | 5 +++-- i.php | 1 + include/config_default.inc.php | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/action.php b/action.php index 31e6e8933..4f3e2fac8 100644 --- a/action.php +++ b/action.php @@ -21,6 +21,7 @@ function guess_mime_type($ext) case "jpg": $ctype="image/jpeg"; break; case "png": $ctype="image/png"; break; case "gif": $ctype="image/gif"; break; + case "webp": $ctype="image/webp"; break; case "tiff": case "tif": $ctype="image/tiff"; break; case "txt": $ctype="text/plain"; break; diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index 47d7a54ed..0a46f2dbb 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -221,6 +221,10 @@ SELECT { $file_path.= 'jpg'; } + elseif (IMAGETYPE_WEBP == $type) + { + $file_path.= 'webp'; + } elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types']) { $original_extension = strtolower(get_extension($original_filename)); diff --git a/admin/include/image.class.php b/admin/include/image.class.php index abc17348d..4234f42ed 100644 --- a/admin/include/image.class.php +++ b/admin/include/image.class.php @@ -47,6 +47,7 @@ class pwg_image function __construct($source_filepath, $library=null) { + global $conf; $this->source_filepath = $source_filepath; trigger_notify('load_image_library', array(&$this) ); @@ -58,7 +59,7 @@ class pwg_image $extension = strtolower(get_extension($source_filepath)); - if (!in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) + if (!in_array($extension, $conf['picture_ext'])) { die('[Image] unsupported file extension'); } @@ -810,4 +811,4 @@ class image_gd implements imageInterface } } -?> \ No newline at end of file +?> diff --git a/i.php b/i.php index 2d07a51e6..333c25baa 100644 --- a/i.php +++ b/i.php @@ -357,6 +357,7 @@ function send_derivative($expires) case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break; case ".png": $ctype="image/png"; break; case ".gif": $ctype="image/gif"; break; + case ".webp": $ctype="image/webp"; break; } header("Content-Type: $ctype"); diff --git a/include/config_default.inc.php b/include/config_default.inc.php index bfeec0de4..25b37b279 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -40,7 +40,7 @@ // picture_ext : file extensions for picture file, must be a subset of // file_ext -$conf['picture_ext'] = array('jpg','jpeg','png','gif'); +$conf['picture_ext'] = array('jpg','jpeg','png','gif','webp'); // file_ext : file extensions (case sensitive) authorized //