From 23a93e0e068d26920fac0de4be8714dc7149d8e7 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Mon, 5 Jan 2026 08:30:07 +0000 Subject: [PATCH] Use MIME type instead of the is_pdf flag to detect PDFs when generating thumbnails (#43451). Patch by Go MAEDA (user:maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@24266 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 1 + lib/redmine/thumbnail.rb | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 07348cd61..d0dd3a71f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -246,6 +246,7 @@ class Attachment < ApplicationRecord 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 diff --git a/lib/redmine/thumbnail.rb b/lib/redmine/thumbnail.rb index 91d6a6fed..cd617487a 100644 --- a/lib/redmine/thumbnail.rb +++ b/lib/redmine/thumbnail.rb @@ -33,21 +33,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 unless 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}"