diff --git a/application/Espo/EntryPoints/Image.php b/application/Espo/EntryPoints/Image.php index e8551e7762..2cd986d976 100644 --- a/application/Espo/EntryPoints/Image.php +++ b/application/Espo/EntryPoints/Image.php @@ -42,6 +42,7 @@ class Image extends \Espo\Core\EntryPoints\Base 'image/jpeg', 'image/png', 'image/gif', + 'image/webp', ]; protected $imageSizes = [ @@ -134,6 +135,9 @@ class Image extends \Espo\Core\EntryPoints\Base case 'image/gif': imagegif($targetImage); break; + case 'image/webp': + imagewebp($targetImage); + break; } $contents = ob_get_contents(); ob_end_clean(); @@ -214,6 +218,10 @@ class Image extends \Espo\Core\EntryPoints\Base $sourceImage = imagecreatefromgif($filePath); imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $originalWidth, $originalHeight); break; + case 'image/webp': + $sourceImage = imagecreatefromwebp($filePath); + imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $originalWidth, $originalHeight); + break; } if (in_array($fileType, $this->fixOrientationFileTypeList)) { diff --git a/application/Espo/Services/Attachment.php b/application/Espo/Services/Attachment.php index d0457608f3..a6bf5f5855 100644 --- a/application/Espo/Services/Attachment.php +++ b/application/Espo/Services/Attachment.php @@ -44,6 +44,13 @@ class Attachment extends Record protected $inlineAttachmentFieldTypeList = ['wysiwyg']; + protected $imageTypeList = [ + 'image/png', + 'image/jpeg', + 'image/gif', + 'image/webp', + ]; + public function upload($fileData) { if (!$this->getAcl()->checkScope('Attachment', 'create')) { @@ -322,7 +329,8 @@ class Attachment extends Record 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', - 'gif' => 'image/gif' + 'gif' => 'image/gif', + 'webp' => 'image/webp', ]; $extension = preg_replace('#\?.*#', '', pathinfo($url, \PATHINFO_EXTENSION)); @@ -334,7 +342,7 @@ class Attachment extends Record if (!$type) return; - if (!in_array($type, ['image/png', 'image/jpeg', 'image/gif'])) { + if (!in_array($type, $this->imageTypeList)) { return; } diff --git a/client/src/views/fields/attachment-multiple.js b/client/src/views/fields/attachment-multiple.js index b89fc1a655..220ec3a7ee 100644 --- a/client/src/views/fields/attachment-multiple.js +++ b/client/src/views/fields/attachment-multiple.js @@ -56,6 +56,7 @@ Espo.define('views/fields/attachment-multiple', 'views/fields/base', function (D 'image/jpeg', 'image/png', 'image/gif', + 'image/webp', ], validations: ['ready', 'required'], @@ -284,11 +285,8 @@ Espo.define('views/fields/attachment-multiple', 'views/fields/base', function (D var preview = name; - switch (type) { - case 'image/png': - case 'image/jpeg': - case 'image/gif': - preview = ''; + if (~this.previewTypeList.indexOf(type)) { + preview = ''; } return preview; @@ -490,11 +488,8 @@ Espo.define('views/fields/attachment-multiple', 'views/fields/base', function (D }, isTypeIsImage: function (type) { - switch (type) { - case 'image/png': - case 'image/jpeg': - case 'image/gif': - return true; + if (~this.previewTypeList.indexOf(type)) { + return true; } return false }, diff --git a/client/src/views/fields/file.js b/client/src/views/fields/file.js index 1e0085aeb4..a73bacd963 100644 --- a/client/src/views/fields/file.js +++ b/client/src/views/fields/file.js @@ -46,6 +46,7 @@ Espo.define('views/fields/file', 'views/fields/link', function (Dep) { 'image/jpeg', 'image/png', 'image/gif', + 'image/webp', ], defaultType: false, @@ -247,11 +248,8 @@ Espo.define('views/fields/file', 'views/fields/link', function (Dep) { name = Handlebars.Utils.escapeExpression(name); var preview = name; - switch (type) { - case 'image/png': - case 'image/jpeg': - case 'image/gif': - preview = ''; + if (~this.previewTypeList.indexOf(type)) { + preview = ''; } return preview; }, @@ -260,11 +258,8 @@ Espo.define('views/fields/file', 'views/fields/link', function (Dep) { name = Handlebars.Utils.escapeExpression(name); var preview = name; - switch (type) { - case 'image/png': - case 'image/jpeg': - case 'image/gif': - preview = ''; + if (~this.previewTypeList.indexOf(type)) { + preview = ''; } return preview;