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))
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?
'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',
('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)
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
'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
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
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")