* 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-8f06a7374b81tags/5.1.0
@@ -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)) |
@@ -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? |
@@ -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', |
@@ -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) |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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") |