Support AVIF images (#43943).

Patch by Go MAEDA (user:maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@24581 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2026-04-15 01:02:01 +00:00
parent 834e74d957
commit 195185a4e0
7 changed files with 8 additions and 3 deletions

View File

@@ -227,7 +227,7 @@ class Attachment < ApplicationRecord
end
def image?
!!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp)$/i)
!!(self.filename =~ /\.(avif|bmp|gif|jpg|jpe|jpeg|png|webp)$/i)
end
def thumbnailable?

View File

@@ -39,6 +39,7 @@ module Redmine
'text/yaml' => 'yml,yaml',
'text/csv' => 'csv',
'text/x-po' => 'po',
'image/avif' => 'avif',
'image/gif' => 'gif',
'image/jpeg' => 'jpg,jpeg,jpe',
'image/png' => 'png',

View File

@@ -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/avif image/bmp image/gif image/jpeg image/png image/webp application/pdf)
# Generates a thumbnail for the source image to target
# TODO: Remove the deprecated _is_pdf parameter in Redmine 7.0

View File

@@ -51,7 +51,7 @@ module Redmine
src = node['src']
if src =~ %r{\A(?<filename>[^/"]+?\.(?:bmp|gif|jpg|jpeg|jpe|png|webp))\z}i
if src =~ %r{\A(?<filename>[^/"]+?\.(?:avif|bmp|gif|jpg|jpeg|jpe|png|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)

View 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.avif').thumbnailable?
assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable?
assert_equal true, Attachment.new(:filename => 'test.webp').thumbnailable?
end

View File

@@ -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

View File

@@ -35,6 +35,7 @@ class Redmine::WikiFormatting::InlineAttachmentsScrubberTest < Redmine::HelperTe
def test_should_resolve_attached_images
to_test = [
"test.avif",
"test.bmp",
"test.gif",
"test.jpg",