From: Go MAEDA Date: Mon, 16 Jan 2023 01:23:36 +0000 (+0000) Subject: Support for WebP images (#38168). X-Git-Tag: 5.1.0~284 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=91705e083beeece533afcad8b7285f6698c2a6da;p=redmine.git Support for WebP images (#38168). * Inline image * Thumbnail * Inserting markup for an image uploaded by drag and drop Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@22045 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fac31d569..72d9d8efd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -944,7 +944,7 @@ module ApplicationHelper attachments += obj.attachments if obj.respond_to?(:attachments) end if attachments.present? - text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| + text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png|webp))"(\s+alt="([^"]*)")?/i) do |m| filename, ext, alt, alttext = $1, $2, $3, $4 # search for the picture in attachments if found = Attachment.latest_attach(attachments, CGI.unescape(filename)) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 980890643..86382054d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -220,7 +220,7 @@ class Attachment < ActiveRecord::Base end def image? - !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i) + !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp)$/i) end def thumbnailable? diff --git a/lib/redmine/mime_type.rb b/lib/redmine/mime_type.rb index 65d15aa4b..679c9aa8d 100644 --- a/lib/redmine/mime_type.rb +++ b/lib/redmine/mime_type.rb @@ -44,6 +44,7 @@ module Redmine 'image/jpeg' => 'jpg,jpeg,jpe', 'image/png' => 'png', 'image/tiff' => 'tiff,tif', + 'image/webp' => 'webp', 'image/x-ms-bmp' => 'bmp', 'application/javascript' => 'js', 'application/pdf' => 'pdf', diff --git a/lib/redmine/thumbnail.rb b/lib/redmine/thumbnail.rb index 0b1333d1a..a777ed9e8 100644 --- a/lib/redmine/thumbnail.rb +++ b/lib/redmine/thumbnail.rb @@ -29,7 +29,7 @@ module Redmine ('gswin64c' if Redmine::Platform.mswin?) || 'gs' ).freeze - ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png application/pdf) + ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/webp application/pdf) # Generates a thumbnail for the source image to target def self.generate(source, target, size, is_pdf = false) diff --git a/test/fixtures/attachments.yml b/test/fixtures/attachments.yml index 3805df02e..0b4558aac 100644 --- a/test/fixtures/attachments.yml +++ b/test/fixtures/attachments.yml @@ -309,3 +309,17 @@ attachments_023: filename: ecookbook-gantt.pdf author_id: 2 description: Gantt chart as of May 11 +attachments_024: + created_on: 2023-01-11 08:46:41 +00:00 + content_type: image/webp + container_type: WikiPage + container_id: 1 + downloads: 0 + disk_filename: 230111173947_logo.webp + disk_directory: "2023/01" + digest: 9219249de57e601a0bb65845304bc44bb1961ea1c2b8ace28c38fa40c3c741e5 + id: 24 + filesize: 74974 + filename: logo.webp + author_id: 2 + description: WebP image diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index cf7c4ff3a..ff62525f2 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -184,6 +184,8 @@ class ApplicationHelperTest < Redmine::HelperTest 'Inline image: This is a logo', 'Inline image: !logo.GIF!' => 'Inline image: This is a logo', + 'Inline WebP image: !logo.webp!' => + 'Inline WebP image: WebP image', 'No match: !ogo.gif!' => 'No match: ', 'No match: !ogo.GIF!' => 'No match: ', # link image diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index d4ef2f7cd..891e6145a 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -520,6 +520,7 @@ class AttachmentTest < ActiveSupport::TestCase def test_thumbnailable_should_be_true_for_images skip unless convert_installed? assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable? + assert_equal true, Attachment.new(:filename => 'test.webp').thumbnailable? end def test_thumbnailable_should_be_false_for_images_if_convert_is_unavailable diff --git a/test/unit/lib/redmine/mime_type_test.rb b/test/unit/lib/redmine/mime_type_test.rb index cbf1d3dec..943fef03c 100644 --- a/test/unit/lib/redmine/mime_type_test.rb +++ b/test/unit/lib/redmine/mime_type_test.rb @@ -77,6 +77,12 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase end end + def test_by_type + image_types = Redmine::MimeType.by_type('image') + assert_includes image_types, 'image/png' + assert_includes image_types, 'image/webp' + end + def test_should_default_to_mime_type_gem assert !Redmine::MimeType::EXTENSIONS.key?("zip") assert_equal "application/zip", Redmine::MimeType.of("file.zip")