Test if convert binary is available.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10014 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
537be80be2
commit
fe95692f10
@ -21,16 +21,18 @@ module Redmine
|
|||||||
module Thumbnail
|
module Thumbnail
|
||||||
extend Redmine::Utils::Shell
|
extend Redmine::Utils::Shell
|
||||||
|
|
||||||
|
CONVERT_BIN = (Redmine::Configuration['imagemagick_convert_command'] || 'convert').freeze
|
||||||
|
|
||||||
# Generates a thumbnail for the source image to target
|
# Generates a thumbnail for the source image to target
|
||||||
def self.generate(source, target, size)
|
def self.generate(source, target, size)
|
||||||
|
return nil unless convert_available?
|
||||||
unless File.exists?(target)
|
unless File.exists?(target)
|
||||||
directory = File.dirname(target)
|
directory = File.dirname(target)
|
||||||
unless File.exists?(directory)
|
unless File.exists?(directory)
|
||||||
FileUtils.mkdir_p directory
|
FileUtils.mkdir_p directory
|
||||||
end
|
end
|
||||||
bin = Redmine::Configuration['imagemagick_convert_command'] || 'convert'
|
|
||||||
size_option = "#{size}x#{size}>"
|
size_option = "#{size}x#{size}>"
|
||||||
cmd = "#{shell_quote bin} #{shell_quote source} -thumbnail #{shell_quote size_option} #{shell_quote target}"
|
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -thumbnail #{shell_quote size_option} #{shell_quote target}"
|
||||||
unless system(cmd)
|
unless system(cmd)
|
||||||
logger.error("Creating thumbnail failed (#{$?}):\nCommand: #{cmd}")
|
logger.error("Creating thumbnail failed (#{$?}):\nCommand: #{cmd}")
|
||||||
return nil
|
return nil
|
||||||
@ -39,6 +41,14 @@ module Redmine
|
|||||||
target
|
target
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.convert_available?
|
||||||
|
return @convert_available if defined?(@convert_available)
|
||||||
|
logger.warn("testing for convert...")
|
||||||
|
@convert_available = system("#{shell_quote CONVERT_BIN} -version") rescue false
|
||||||
|
logger.warn("Imagemagick's convert binary (#{CONVERT_BIN}) not available") unless @convert_available
|
||||||
|
@convert_available
|
||||||
|
end
|
||||||
|
|
||||||
def self.logger
|
def self.logger
|
||||||
Rails.logger
|
Rails.logger
|
||||||
end
|
end
|
||||||
|
@ -129,10 +129,7 @@ class ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.convert_installed?
|
def self.convert_installed?
|
||||||
bin = Redmine::Configuration['imagemagick_convert_command'] || 'convert'
|
Redmine::Thumbnail.convert_available?
|
||||||
system("#{bin} -version")
|
|
||||||
rescue
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the path to the test +vendor+ repository
|
# Returns the path to the test +vendor+ repository
|
||||||
|
Loading…
x
Reference in New Issue
Block a user