forked from minimagick/minimagick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_magick.rb
More file actions
87 lines (77 loc) · 2.04 KB
/
Copy pathmini_magick.rb
File metadata and controls
87 lines (77 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'tempfile'
require 'subexec'
require 'stringio'
require 'pathname'
require 'shellwords'
require 'mini_magick/command_builder'
require 'mini_magick/errors'
require 'mini_magick/image'
require 'mini_magick/utilities'
module MiniMagick
@validate_on_create = true
@validate_on_write = true
class << self
attr_accessor :processor
attr_accessor :processor_path
attr_accessor :timeout
attr_accessor :validate_on_create
attr_accessor :validate_on_write
##
# Tries to detect the current processor based if any of the processors exist.
# Mogrify have precedence over gm by default.
#
# === Returns
# * [String] The detected procesor
def choose_processor
self.processor = if MiniMagick::Utilities.which('mogrify')
"mogrify"
elsif MiniMagick::Utilities.which('gm')
"gm"
else
nil
end
end
##
# Discovers the imagemagick version based on mogrify's output.
#
# === Returns
# * The imagemagick version
def image_magick_version
@@version ||= Gem::Version.create(`mogrify --version`.split(" ")[2].split("-").first)
end
##
# The minimum allowed imagemagick version
#
# === Returns
# * The minimum imagemagick version
def minimum_image_magick_version
@@minimum_version ||= Gem::Version.create("6.6.3")
end
##
# Checks whether the imagemagick's version is valid
#
# === Returns
# * [Boolean]
def valid_version_installed?
image_magick_version >= minimum_image_magick_version
end
##
# Picks the right processor if it isn't set and returns whether it's mogrify or not.
#
# === Returns
# * [Boolean]
def mogrify?
self.choose_processor if self.processor.nil?
self.processor == 'mogrify'
end
##
# Picks the right processor if it isn't set and returns whether it's graphicsmagick or not.
#
# === Returns
# * [Boolean]
def gm?
self.choose_processor if self.processor.nil?
self.processor == 'gm'
end
end
end