summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-16 17:15:40 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-16 17:15:40 +0000
commit537be80be26c38d5384d588873d2682fd908ee62 (patch)
tree0f4a60940759a5ad8d86bebcd17b36649b02dfc8 /app
parent5c2de4dfc95293a7965ff8cf980a310922fc4c05 (diff)
downloadredmine-537be80be26c38d5384d588873d2682fd908ee62.tar.gz
redmine-537be80be26c38d5384d588873d2682fd908ee62.zip
Adds a macro for inserting thumbnails in formatted text (#3510).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10013 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/attachments_controller.rb2
-rw-r--r--app/models/attachment.rb12
2 files changed, 11 insertions, 3 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index edae9b0cc..74a11a1c7 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -61,7 +61,7 @@ class AttachmentsController < ApplicationController
end
def thumbnail
- if @attachment.thumbnailable? && Setting.thumbnails_enabled? && thumbnail = @attachment.thumbnail
+ if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size])
if stale?(:etag => thumbnail)
send_file thumbnail,
:filename => filename_for_content_disposition(@attachment.filename),
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 9aeee07d0..a1c232d16 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -171,9 +171,17 @@ class Attachment < ActiveRecord::Base
# Returns the full path the attachment thumbnail, or nil
# if the thumbnail cannot be generated.
- def thumbnail
+ def thumbnail(options={})
if thumbnailable? && readable?
- size = Setting.thumbnails_size.to_i
+ size = options[:size].to_i
+ if size > 0
+ # Limit the number of thumbnails per image
+ size = (size / 50) * 50
+ # Maximum thumbnail size
+ size = 800 if size > 800
+ else
+ size = Setting.thumbnails_size.to_i
+ end
size = 100 unless size > 0
target = File.join(self.class.thumbnails_storage_path, "#{id}_#{digest}_#{size}.thumb")