From e78033d774145bd599a00ed5a8a1dcb49a3fb996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 22 Sep 2019 21:25:06 +0200 Subject: [PATCH] Treat all image formats that browsers can show correctly as image attachments. Especially we can now use WebP for attachments. --- src/Entity/Attachments/Attachment.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 1f6f3920..81e0ea23 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -40,6 +40,15 @@ use Doctrine\ORM\Mapping as ORM; */ abstract class Attachment extends NamedDBElement { + + /** + * A list of file extensions, that browsers can show directly as image. + * Based on: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types + * It will be used to determine if a attachment is a picture and therefore will be shown to user as preview. + */ + const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png', + 'svg', 'webp']; + /** * @var bool * @ORM\Column(type="boolean") @@ -85,10 +94,7 @@ abstract class Attachment extends NamedDBElement $extension = pathinfo($this->getPath(), PATHINFO_EXTENSION); - // list all file extensions which are supported to display them by HTML code - $picture_extensions = array('gif', 'png', 'jpg', 'jpeg', 'bmp', 'svg', 'tif'); - - return in_array(strtolower($extension), $picture_extensions, true); + return in_array(strtolower($extension), static::PICTURE_EXTS, true); } /**