@@ -21,16 +21,18 module Redmine | |||
|
21 | 21 | module Thumbnail |
|
22 | 22 | extend Redmine::Utils::Shell |
|
23 | 23 | |
|
24 | CONVERT_BIN = (Redmine::Configuration['imagemagick_convert_command'] || 'convert').freeze | |
|
25 | ||
|
24 | 26 | # Generates a thumbnail for the source image to target |
|
25 | 27 | def self.generate(source, target, size) |
|
28 | return nil unless convert_available? | |
|
26 | 29 | unless File.exists?(target) |
|
27 | 30 | directory = File.dirname(target) |
|
28 | 31 | unless File.exists?(directory) |
|
29 | 32 | FileUtils.mkdir_p directory |
|
30 | 33 | end |
|
31 | bin = Redmine::Configuration['imagemagick_convert_command'] || 'convert' | |
|
32 | 34 | size_option = "#{size}x#{size}>" |
|
33 |
cmd = "#{shell_quote |
|
|
35 | cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -thumbnail #{shell_quote size_option} #{shell_quote target}" | |
|
34 | 36 | unless system(cmd) |
|
35 | 37 | logger.error("Creating thumbnail failed (#{$?}):\nCommand: #{cmd}") |
|
36 | 38 | return nil |
@@ -39,6 +41,14 module Redmine | |||
|
39 | 41 | target |
|
40 | 42 | end |
|
41 | 43 | |
|
44 | def self.convert_available? | |
|
45 | return @convert_available if defined?(@convert_available) | |
|
46 | logger.warn("testing for convert...") | |
|
47 | @convert_available = system("#{shell_quote CONVERT_BIN} -version") rescue false | |
|
48 | logger.warn("Imagemagick's convert binary (#{CONVERT_BIN}) not available") unless @convert_available | |
|
49 | @convert_available | |
|
50 | end | |
|
51 | ||
|
42 | 52 | def self.logger |
|
43 | 53 | Rails.logger |
|
44 | 54 | end |
@@ -129,10 +129,7 class ActiveSupport::TestCase | |||
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | def self.convert_installed? |
|
132 | bin = Redmine::Configuration['imagemagick_convert_command'] || 'convert' | |
|
133 | system("#{bin} -version") | |
|
134 | rescue | |
|
135 | false | |
|
132 | Redmine::Thumbnail.convert_available? | |
|
136 | 133 | end |
|
137 | 134 | |
|
138 | 135 | # Returns the path to the test +vendor+ repository |
General Comments 0
You need to be logged in to leave comments.
Login now