Project

General

Profile

Feature #43943 ยป 0001-Support-AVIF-images.patch

Go MAEDA, 2026-04-10 07:28

View differences:

app/models/attachment.rb
227 227
  end
228 228

  
229 229
  def image?
230
    !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp)$/i)
230
    !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|avif|webp)$/i)
231 231
  end
232 232

  
233 233
  def thumbnailable?
lib/redmine/mime_type.rb
43 43
      'image/jpeg' => 'jpg,jpeg,jpe',
44 44
      'image/png' => 'png',
45 45
      'image/tiff' => 'tiff,tif',
46
      'image/avif' => 'avif',
46 47
      'image/webp' => 'webp',
47 48
      'image/x-ms-bmp' => 'bmp',
48 49
      'application/javascript' => 'js',
lib/redmine/thumbnail.rb
30 30
      ('gswin64c' if Redmine::Platform.mswin?) ||
31 31
      'gs'
32 32
    ).freeze
33
    ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/webp application/pdf)
33
    ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/avif image/webp application/pdf)
34 34

  
35 35
    # Generates a thumbnail for the source image to target
36 36
    # TODO: Remove the deprecated _is_pdf parameter in Redmine 7.0
lib/redmine/wiki_formatting/inline_attachments_scrubber.rb
51 51

  
52 52
        src = node['src']
53 53

  
54
        if src =~ %r{\A(?<filename>[^/"]+?\.(?:bmp|gif|jpg|jpeg|jpe|png|webp))\z}i
54
        if src =~ %r{\A(?<filename>[^/"]+?\.(?:bmp|gif|jpg|jpeg|jpe|png|avif|webp))\z}i
55 55
          filename = $~[:filename]
56 56
          if found = find_attachment(CGI.unescape(filename))
57 57
            image_url = @view.download_named_attachment_url(found, found.filename, :only_path => @only_path)
test/unit/attachment_test.rb
520 520

  
521 521
  def test_thumbnailable_should_be_true_for_images
522 522
    skip unless convert_installed?
523
    assert_equal true, Attachment.new(:filename => 'test.avif').thumbnailable?
523 524
    assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable?
524 525
    assert_equal true, Attachment.new(:filename => 'test.webp').thumbnailable?
525 526
  end
test/unit/lib/redmine/mime_type_test.rb
24 24
    to_test = {
25 25
      'test.txt' => 'text/plain',
26 26
      'test.c' => 'text/x-c',
27
      'test.avif' => 'image/avif',
27 28
      'TEST.JPG' => 'image/jpeg',
28 29
    }
29 30
    to_test.each do |name, expected|
......
79 80

  
80 81
  def test_by_type
81 82
    image_types = Redmine::MimeType.by_type('image')
83
    assert_includes image_types, 'image/avif'
82 84
    assert_includes image_types, 'image/png'
83 85
    assert_includes image_types, 'image/webp'
84 86
  end
test/unit/lib/redmine/wiki_formatting/inline_attachments_scrubber_test.rb
41 41
      "test.jpeg",
42 42
      "test.jpe",
43 43
      "test.png",
44
      "test.avif",
44 45
      "test.webp"
45 46
    ]
46 47

  
    (1-1/1)