Feature #38168 ยป webp.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
| 944 | 944 |
attachments += obj.attachments if obj.respond_to?(:attachments) |
| 945 | 945 |
end |
| 946 | 946 |
if attachments.present? |
| 947 |
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| |
|
| 947 |
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png|webp))"(\s+alt="([^"]*)")?/i) do |m|
|
|
| 948 | 948 |
filename, ext, alt, alttext = $1, $2, $3, $4 |
| 949 | 949 |
# search for the picture in attachments |
| 950 | 950 |
if found = Attachment.latest_attach(attachments, CGI.unescape(filename)) |
| app/models/attachment.rb | ||
|---|---|---|
| 220 | 220 |
end |
| 221 | 221 | |
| 222 | 222 |
def image? |
| 223 |
!!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i) |
|
| 223 |
!!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp)$/i)
|
|
| 224 | 224 |
end |
| 225 | 225 | |
| 226 | 226 |
def thumbnailable? |
| lib/redmine/mime_type.rb | ||
|---|---|---|
| 44 | 44 |
'image/jpeg' => 'jpg,jpeg,jpe', |
| 45 | 45 |
'image/png' => 'png', |
| 46 | 46 |
'image/tiff' => 'tiff,tif', |
| 47 |
'image/webp' => 'webp', |
|
| 47 | 48 |
'image/x-ms-bmp' => 'bmp', |
| 48 | 49 |
'application/javascript' => 'js', |
| 49 | 50 |
'application/pdf' => 'pdf', |
| lib/redmine/thumbnail.rb | ||
|---|---|---|
| 29 | 29 |
('gswin64c' if Redmine::Platform.mswin?) ||
|
| 30 | 30 |
'gs' |
| 31 | 31 |
).freeze |
| 32 |
ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png application/pdf) |
|
| 32 |
ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/webp application/pdf)
|
|
| 33 | 33 | |
| 34 | 34 |
# Generates a thumbnail for the source image to target |
| 35 | 35 |
def self.generate(source, target, size, is_pdf = false) |
| test/fixtures/attachments.yml | ||
|---|---|---|
| 309 | 309 |
filename: ecookbook-gantt.pdf |
| 310 | 310 |
author_id: 2 |
| 311 | 311 |
description: Gantt chart as of May 11 |
| 312 |
attachments_024: |
|
| 313 |
created_on: 2023-01-11 08:46:41 +00:00 |
|
| 314 |
content_type: image/webp |
|
| 315 |
container_type: Issue |
|
| 316 |
container_id: 1 |
|
| 317 |
downloads: 0 |
|
| 318 |
disk_filename: 230111173947_logo.webp |
|
| 319 |
disk_directory: "2023/01" |
|
| 320 |
digest: 9219249de57e601a0bb65845304bc44bb1961ea1c2b8ace28c38fa40c3c741e5 |
|
| 321 |
id: 24 |
|
| 322 |
filesize: 74974 |
|
| 323 |
filename: logo.webp |
|
| 324 |
author_id: 2 |
|
| 325 |
description: WebP image |
|
| test/helpers/application_helper_test.rb | ||
|---|---|---|
| 184 | 184 |
'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" />', |
| 185 | 185 |
'Inline image: !logo.GIF!' => |
| 186 | 186 |
'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" />', |
| 187 |
'Inline WebP image: !logo.webp!' => |
|
| 188 |
'Inline WebP image: <img src="/attachments/download/24/logo.webp" title="WebP image" alt="WebP image" loading="lazy" />', |
|
| 187 | 189 |
'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />', |
| 188 | 190 |
'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />', |
| 189 | 191 |
# link image |
| test/unit/attachment_test.rb | ||
|---|---|---|
| 520 | 520 |
def test_thumbnailable_should_be_true_for_images |
| 521 | 521 |
skip unless convert_installed? |
| 522 | 522 |
assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable? |
| 523 |
assert_equal true, Attachment.new(:filename => 'test.webp').thumbnailable? |
|
| 523 | 524 |
end |
| 524 | 525 | |
| 525 | 526 |
def test_thumbnailable_should_be_false_for_images_if_convert_is_unavailable |
| test/unit/lib/redmine/mime_type_test.rb | ||
|---|---|---|
| 77 | 77 |
end |
| 78 | 78 |
end |
| 79 | 79 | |
| 80 |
def test_by_type |
|
| 81 |
image_types = Redmine::MimeType.by_type('image')
|
|
| 82 |
assert_includes image_types, 'image/png' |
|
| 83 |
assert_includes image_types, 'image/webp' |
|
| 84 |
end |
|
| 85 | ||
| 80 | 86 |
def test_should_default_to_mime_type_gem |
| 81 | 87 |
assert !Redmine::MimeType::EXTENSIONS.key?("zip")
|
| 82 | 88 |
assert_equal "application/zip", Redmine::MimeType.of("file.zip")
|