Treat all image formats that browsers can show correctly as image attachments.

Especially we can now use WebP for attachments.
This commit is contained in:
Jan Böhmer 2019-09-22 21:25:06 +02:00
parent e4f5afb628
commit e78033d774

View file

@ -40,6 +40,15 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
abstract class Attachment extends NamedDBElement 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 * @var bool
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")
@ -85,10 +94,7 @@ abstract class Attachment extends NamedDBElement
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION); $extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
// list all file extensions which are supported to display them by HTML code return in_array(strtolower($extension), static::PICTURE_EXTS, true);
$picture_extensions = array('gif', 'png', 'jpg', 'jpeg', 'bmp', 'svg', 'tif');
return in_array(strtolower($extension), $picture_extensions, true);
} }
/** /**