Merge r24266 from trunk to 5.1-stable (#43451).

git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@24272 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu
2026-01-05 08:36:22 +00:00
parent e488a205eb
commit cf395af206
2 changed files with 5 additions and 4 deletions

View File

@@ -246,6 +246,7 @@ class Attachment < ActiveRecord::Base
target = thumbnail_path(size)
begin
# TODO: Stop passing the deprecated is_pdf flag in Redmine 7.0
Redmine::Thumbnail.generate(self.diskfile, target, size, is_pdf?)
rescue => e
if logger

View File

@@ -32,21 +32,21 @@ module Redmine
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)
# TODO: Remove the deprecated _is_pdf parameter in Redmine 7.0
def self.generate(source, target, size, _is_pdf = nil)
return nil unless convert_available?
return nil if is_pdf && !gs_available?
unless File.exist?(target)
# Make sure we only invoke Imagemagick if the file type is allowed
mime_type = File.open(source) {|f| Marcel::MimeType.for(f)}
return nil if !ALLOWED_TYPES.include? mime_type
return nil if is_pdf && mime_type != "application/pdf"
return nil if mime_type == 'application/pdf' && !gs_available?
directory = File.dirname(target)
FileUtils.mkdir_p directory
size_option = "#{size}x#{size}>"
if is_pdf
if mime_type == 'application/pdf'
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote "#{source}[0]"} -thumbnail #{shell_quote size_option} #{shell_quote "png:#{target}"}"
else
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote target}"