summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-05-12 03:55:56 +0000
committerGo MAEDA <maeda@farend.jp>2019-05-12 03:55:56 +0000
commitc4a4133178b83c2c115df1947302c785b2885467 (patch)
tree10aeb523e06a613a9b8942b67cae947a23b2b4e9 /app
parenta5b9632772294981b5c96fb5f8273a386d84f90c (diff)
downloadredmine-c4a4133178b83c2c115df1947302c785b2885467.tar.gz
redmine-c4a4133178b83c2c115df1947302c785b2885467.zip
Render PDF thumbnail using ImageMagick/GhostScript (#22481).
Patch by Gregor Schmidt. git-svn-id: http://svn.redmine.org/redmine/trunk@18158 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_controller.rb3
-rw-r--r--app/controllers/attachments_controller.rb16
-rw-r--r--app/models/attachment.rb4
3 files changed, 16 insertions, 7 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 91d3b0712..eb2288eff 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -77,7 +77,8 @@ class AdminController < ApplicationController
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
["#{l :text_plugin_assets_writable} (./public/plugin_assets)", File.writable?(Redmine::Plugin.public_directory)],
[:text_rmagick_available, Object.const_defined?(:Magick)],
- [:text_convert_available, Redmine::Thumbnail.convert_available?]
+ [:text_convert_available, Redmine::Thumbnail.convert_available?],
+ [:text_gs_available, Redmine::Thumbnail.gs_available?]
]
end
end
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index bc558fdc0..4817149a4 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -83,7 +83,7 @@ class AttachmentsController < ApplicationController
if stale?(:etag => tbnail)
send_file tbnail,
:filename => filename_for_content_disposition(@attachment.filename),
- :type => detect_content_type(@attachment),
+ :type => detect_content_type(@attachment, true),
:disposition => 'inline'
end
else
@@ -236,12 +236,20 @@ class AttachmentsController < ApplicationController
@attachment.deletable? ? true : deny_access
end
- def detect_content_type(attachment)
+ def detect_content_type(attachment, is_thumb = false)
content_type = attachment.content_type
if content_type.blank? || content_type == "application/octet-stream"
- content_type = Redmine::MimeType.of(attachment.filename)
+ content_type =
+ Redmine::MimeType.of(attachment.filename).presence ||
+ "application/octet-stream"
end
- content_type.presence || "application/octet-stream"
+
+ if is_thumb && content_type == "application/pdf"
+ # PDF previews are stored in PNG format
+ content_type = "image/png"
+ end
+
+ content_type
end
def disposition(attachment)
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 362ac1fde..a0d712a34 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -201,7 +201,7 @@ class Attachment < ActiveRecord::Base
end
def thumbnailable?
- image?
+ image? || (is_pdf? && Redmine::Thumbnail.gs_available?)
end
# Returns the full path the attachment thumbnail, or nil
@@ -221,7 +221,7 @@ class Attachment < ActiveRecord::Base
target = thumbnail_path(size)
begin
- Redmine::Thumbnail.generate(self.diskfile, target, size)
+ Redmine::Thumbnail.generate(self.diskfile, target, size, is_pdf?)
rescue => e
logger.error "An error occured while generating thumbnail for #{disk_filename} to #{target}\nException was: #{e.message}" if logger
return nil