My-Little-Forum / mylittleforum

A simple PHP and MySQL based internet forum that displays the messages in classical threaded view (tree structure)
GNU General Public License v3.0
124 stars 48 forks source link

WebP support for image upload #623

Closed auge8472 closed 2 years ago

auge8472 commented 2 years ago

Because of a request in the project forum I researched the conditions for supporting WebP-images in the image-upload-feature. It was a sitting duck to adapt the existing code because creation a WebP-image works similar to the equivalent functions for GIF-, JPEG- or PNG-images. Furthermore I changed the file type detection for images because using getimagesize for this purpose is not recommeded anymore.

"Do not use getimagesize() to check that a given file is a valid image. Use a purpose-built solution such as the Fileinfo extension instead."

The file-type-check is now based on the MIME-type. As a side effect of this change it is theoretically possible to allow further file types to be uploaded.


I tested the functionallity in a testing instance of the forum. The upload-script accepts WebP-images generally and it also resamples to large source images with lossy compression. That way I downsized a to large source image (1384x1341px, 1.7 MB) to 1024x990px with a filesize of 123kB [^1] without any obviously visible compression artifacts, as it is common with highly compressed JPEG-images.

[^1]: The settings for uploading images in my testing instance allows images with dimensions up to 1024px and a maximal file size of 200kB.