]> source.dussan.org Git - redmine.git/commitdiff
Support for WebP images (#38168).
authorGo MAEDA <maeda@farend.jp>
Mon, 16 Jan 2023 01:23:36 +0000 (01:23 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 16 Jan 2023 01:23:36 +0000 (01:23 +0000)
* 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

app/helpers/application_helper.rb
app/models/attachment.rb
lib/redmine/mime_type.rb
lib/redmine/thumbnail.rb
test/fixtures/attachments.yml
test/helpers/application_helper_test.rb
test/unit/attachment_test.rb
test/unit/lib/redmine/mime_type_test.rb

index fac31d569d11de16828aa782e4ccac932dd4e08b..72d9d8efdb85e61e73484f53df9c4b4691d6dcfd 100644 (file)
@@ -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))
index 98089064313073e5c257d2e3c527f9ee3acab31c..86382054da2a10ef225e25dce483fcf560d82705 100644 (file)
@@ -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?
index 65d15aa4bb5047f0fc733e654b2569e164bb7777..679c9aa8de48a88b903254008581ab29fc25ce2d 100644 (file)
@@ -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',
index 0b1333d1a9a3cd21b9ed3e233cfaeb22cf4bd609..a777ed9e8e7083e45c74219dcdec1dd0ba3ab283 100644 (file)
@@ -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)
index 3805df02edc05d88ce50aab79bfce8a4c6cfc94b..0b4558aac610e95bcbcc37814ff970d2356db3e7 100644 (file)
@@ -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
index cf7c4ff3a4a49763137bd7425331f2ce69496191..ff62525f2f3e35004e071ab6f85b224f78aac3b0 100644 (file)
@@ -184,6 +184,8 @@ class ApplicationHelperTest < Redmine::HelperTest
          'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" />',
       'Inline image: !logo.GIF!' =>
          'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" />',
+      'Inline WebP image: !logo.webp!' =>
+         'Inline WebP image: <img src="/attachments/download/24/logo.webp" title="WebP image" alt="WebP image" loading="lazy" />',
       'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
       'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
       # link image
index d4ef2f7cd4b2f76fcdbead92cae966e4c7a3353a..891e6145ab0d224c384b3825b00fc6b4896fb8c5 100644 (file)
@@ -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
index cbf1d3decdcca0d95d963d9a5ca3761fe3a76088..943fef03cf543f6fcb8e38bb91d9f5aa5057517d 100644 (file)
@@ -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")