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