From af84e2af12bd6ea22d08211bb70877db89fb0e60 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Fri, 10 Apr 2026 12:49:32 +0900 Subject: [PATCH] Support AVIF images --- app/models/attachment.rb | 2 +- lib/redmine/mime_type.rb | 1 + lib/redmine/thumbnail.rb | 2 +- lib/redmine/wiki_formatting/inline_attachments_scrubber.rb | 2 +- test/unit/attachment_test.rb | 1 + test/unit/lib/redmine/mime_type_test.rb | 2 ++ .../redmine/wiki_formatting/inline_attachments_scrubber_test.rb | 1 + 7 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 12d4c809c..d5c9911ec 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -227,7 +227,7 @@ class Attachment < ApplicationRecord end def image? - !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp)$/i) + !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|avif|webp)$/i) end def thumbnailable? diff --git a/lib/redmine/mime_type.rb b/lib/redmine/mime_type.rb index 5554cc5a9..fcc4b2e95 100644 --- a/lib/redmine/mime_type.rb +++ b/lib/redmine/mime_type.rb @@ -43,6 +43,7 @@ module Redmine 'image/jpeg' => 'jpg,jpeg,jpe', 'image/png' => 'png', 'image/tiff' => 'tiff,tif', + 'image/avif' => 'avif', 'image/webp' => 'webp', 'image/x-ms-bmp' => 'bmp', 'application/javascript' => 'js', diff --git a/lib/redmine/thumbnail.rb b/lib/redmine/thumbnail.rb index 556680a5a..e6c8f0fa2 100644 --- a/lib/redmine/thumbnail.rb +++ b/lib/redmine/thumbnail.rb @@ -30,7 +30,7 @@ module Redmine ('gswin64c' if Redmine::Platform.mswin?) || 'gs' ).freeze - ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/webp application/pdf) + ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/avif image/webp application/pdf) # Generates a thumbnail for the source image to target # TODO: Remove the deprecated _is_pdf parameter in Redmine 7.0 diff --git a/lib/redmine/wiki_formatting/inline_attachments_scrubber.rb b/lib/redmine/wiki_formatting/inline_attachments_scrubber.rb index 2da380df7..c21df096e 100644 --- a/lib/redmine/wiki_formatting/inline_attachments_scrubber.rb +++ b/lib/redmine/wiki_formatting/inline_attachments_scrubber.rb @@ -51,7 +51,7 @@ module Redmine src = node['src'] - if src =~ %r{\A(?[^/"]+?\.(?:bmp|gif|jpg|jpeg|jpe|png|webp))\z}i + if src =~ %r{\A(?[^/"]+?\.(?:bmp|gif|jpg|jpeg|jpe|png|avif|webp))\z}i filename = $~[:filename] if found = find_attachment(CGI.unescape(filename)) image_url = @view.download_named_attachment_url(found, found.filename, :only_path => @only_path) diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index 1af8eb0f2..387da73c5 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.avif').thumbnailable? assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable? assert_equal true, Attachment.new(:filename => 'test.webp').thumbnailable? end diff --git a/test/unit/lib/redmine/mime_type_test.rb b/test/unit/lib/redmine/mime_type_test.rb index 95aaef034..265146462 100644 --- a/test/unit/lib/redmine/mime_type_test.rb +++ b/test/unit/lib/redmine/mime_type_test.rb @@ -24,6 +24,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase to_test = { 'test.txt' => 'text/plain', 'test.c' => 'text/x-c', + 'test.avif' => 'image/avif', 'TEST.JPG' => 'image/jpeg', } to_test.each do |name, expected| @@ -79,6 +80,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase def test_by_type image_types = Redmine::MimeType.by_type('image') + assert_includes image_types, 'image/avif' assert_includes image_types, 'image/png' assert_includes image_types, 'image/webp' end diff --git a/test/unit/lib/redmine/wiki_formatting/inline_attachments_scrubber_test.rb b/test/unit/lib/redmine/wiki_formatting/inline_attachments_scrubber_test.rb index 2c441c0e5..e0afe3478 100644 --- a/test/unit/lib/redmine/wiki_formatting/inline_attachments_scrubber_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/inline_attachments_scrubber_test.rb @@ -41,6 +41,7 @@ class Redmine::WikiFormatting::InlineAttachmentsScrubberTest < Redmine::HelperTe "test.jpeg", "test.jpe", "test.png", + "test.avif", "test.webp" ] -- 2.50.1