mini_magick 3.8.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/mini_magick.rb CHANGED
@@ -1,89 +1,53 @@
1
- require 'tempfile'
2
- require 'subexec'
3
- require 'stringio'
4
- require 'pathname'
5
- require 'shellwords'
6
- require 'mini_magick/command_builder'
7
- require 'mini_magick/errors'
1
+ require 'mini_magick/configuration'
2
+ require 'mini_magick/tool'
8
3
  require 'mini_magick/image'
9
- require 'mini_magick/utilities'
10
4
 
11
5
  module MiniMagick
12
- @validate_on_create = true
13
- @validate_on_write = true
14
6
 
15
- class << self
16
- attr_accessor :processor
17
- attr_accessor :processor_path
18
- attr_accessor :timeout
19
- attr_accessor :validate_on_create
20
- attr_accessor :validate_on_write
21
-
22
- ##
23
- # Tries to detect the current processor based if any of the processors exist.
24
- # Mogrify have precedence over gm by default.
25
- #
26
- # === Returns
27
- # * [String] The detected procesor
28
- def choose_processor
29
- self.processor = if MiniMagick::Utilities.which('mogrify')
30
- :mogrify
31
- elsif MiniMagick::Utilities.which('gm')
32
- :gm
33
- else
34
- nil
35
- end
36
- end
37
-
38
- ##
39
- # Discovers the imagemagick version based on mogrify's output.
40
- #
41
- # === Returns
42
- # * The imagemagick version
43
- def image_magick_version
44
- @@version ||= Gem::Version.create(`mogrify --version`.split(' ')[2].split('-').first)
45
- end
46
-
47
- ##
48
- # The minimum allowed imagemagick version
49
- #
50
- # === Returns
51
- # * The minimum imagemagick version
52
- def minimum_image_magick_version
53
- @@minimum_version ||= Gem::Version.create('6.6.3')
54
- end
7
+ extend MiniMagick::Configuration
8
+
9
+ ##
10
+ # You might want to execute only certain blocks of processing with a
11
+ # different CLI, because for example that CLI does that particular thing
12
+ # faster. After the block CLI resets to its previous value.
13
+ #
14
+ # @example
15
+ # MiniMagick.with_cli :graphicsmagick do
16
+ # # operations that are better done with GraphicsMagick
17
+ # end
18
+ def self.with_cli(cli)
19
+ old_cli = self.cli
20
+ self.cli = cli
21
+ yield
22
+ self.cli = old_cli
23
+ end
55
24
 
56
- ##
57
- # Checks whether the imagemagick's version is valid
58
- #
59
- # === Returns
60
- # * [Boolean]
61
- def valid_version_installed?
62
- image_magick_version >= minimum_image_magick_version
63
- end
25
+ ##
26
+ # Checks whether the CLI used is ImageMagick.
27
+ #
28
+ # @return [Boolean]
29
+ def self.imagemagick?
30
+ cli == :imagemagick
31
+ end
64
32
 
65
- ##
66
- # Picks the right processor if it isn't set and returns whether it's mogrify or not.
67
- #
68
- # === Returns
69
- # * [Boolean]
70
- def mogrify?
71
- choose_processor if processor.nil?
33
+ ##
34
+ # Checks whether the CLI used is GraphicsMagick.
35
+ #
36
+ # @return [Boolean]
37
+ def self.graphicsmagick?
38
+ cli == :graphicsmagick
39
+ end
72
40
 
73
- return processor.to_s.downcase.to_sym == :mogrify unless processor.nil?
74
- false
75
- end
41
+ ##
42
+ # Returns ImageMagick's/GraphicsMagick's version.
43
+ #
44
+ # @return [String]
45
+ def self.cli_version
46
+ output = MiniMagick::Tool::Identify.new(&:version)
47
+ output[/\d+\.\d+\.\d+(-\d+)?/]
48
+ end
76
49
 
77
- ##
78
- # Picks the right processor if it isn't set and returns whether it's graphicsmagick or not.
79
- #
80
- # === Returns
81
- # * [Boolean]
82
- def gm?
83
- choose_processor if processor.nil?
50
+ class Error < RuntimeError; end
51
+ class Invalid < StandardError; end
84
52
 
85
- return processor.to_s.downcase.to_sym == :gm unless processor.nil?
86
- false
87
- end
88
- end
89
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -9,25 +9,12 @@ authors:
9
9
  - Peter Kieltyka
10
10
  - James Miller
11
11
  - Thiago Fernandes Massa
12
+ - Janko Marohnić
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2014-07-22 00:00:00.000000000 Z
16
+ date: 2015-03-20 00:00:00.000000000 Z
16
17
  dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: subexec
19
- requirement: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - "~>"
22
- - !ruby/object:Gem::Version
23
- version: 0.2.1
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: 0.2.1
31
18
  - !ruby/object:Gem::Dependency
32
19
  name: rake
33
20
  requirement: !ruby/object:Gem::Requirement
@@ -42,36 +29,22 @@ dependencies:
42
29
  - - ">="
43
30
  - !ruby/object:Gem::Version
44
31
  version: '0'
45
- - !ruby/object:Gem::Dependency
46
- name: test-unit
47
- requirement: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- type: :development
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
32
  - !ruby/object:Gem::Dependency
60
33
  name: rspec
61
34
  requirement: !ruby/object:Gem::Requirement
62
35
  requirements:
63
- - - ">="
36
+ - - "~>"
64
37
  - !ruby/object:Gem::Version
65
- version: '0'
38
+ version: 3.1.0
66
39
  type: :development
67
40
  prerelease: false
68
41
  version_requirements: !ruby/object:Gem::Requirement
69
42
  requirements:
70
- - - ">="
43
+ - - "~>"
71
44
  - !ruby/object:Gem::Version
72
- version: '0'
45
+ version: 3.1.0
73
46
  - !ruby/object:Gem::Dependency
74
- name: mocha
47
+ name: posix-spawn
75
48
  requirement: !ruby/object:Gem::Requirement
76
49
  requirements:
77
50
  - - ">="
@@ -84,13 +57,14 @@ dependencies:
84
57
  - - ">="
85
58
  - !ruby/object:Gem::Version
86
59
  version: '0'
87
- description:
60
+ description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
88
61
  email:
89
62
  - probablycorey@gmail.com
90
63
  - hcatlin@gmail.com
91
64
  - peter@nulayer.com
92
65
  - bensie@gmail.com
93
66
  - thiagown@gmail.com
67
+ - janko.marohnic@gmail.com
94
68
  executables: []
95
69
  extensions: []
96
70
  extra_rdoc_files: []
@@ -99,9 +73,23 @@ files:
99
73
  - Rakefile
100
74
  - lib/mini_gmagick.rb
101
75
  - lib/mini_magick.rb
102
- - lib/mini_magick/command_builder.rb
103
- - lib/mini_magick/errors.rb
76
+ - lib/mini_magick/configuration.rb
104
77
  - lib/mini_magick/image.rb
78
+ - lib/mini_magick/image/info.rb
79
+ - lib/mini_magick/logger.rb
80
+ - lib/mini_magick/shell.rb
81
+ - lib/mini_magick/tool.rb
82
+ - lib/mini_magick/tool/animate.rb
83
+ - lib/mini_magick/tool/compare.rb
84
+ - lib/mini_magick/tool/composite.rb
85
+ - lib/mini_magick/tool/conjure.rb
86
+ - lib/mini_magick/tool/convert.rb
87
+ - lib/mini_magick/tool/display.rb
88
+ - lib/mini_magick/tool/identify.rb
89
+ - lib/mini_magick/tool/import.rb
90
+ - lib/mini_magick/tool/mogrify.rb
91
+ - lib/mini_magick/tool/montage.rb
92
+ - lib/mini_magick/tool/stream.rb
105
93
  - lib/mini_magick/utilities.rb
106
94
  - lib/mini_magick/version.rb
107
95
  homepage: https://github.com/minimagick/minimagick
@@ -125,8 +113,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
113
  requirements:
126
114
  - You must have ImageMagick or GraphicsMagick installed
127
115
  rubyforge_project:
128
- rubygems_version: 2.2.2
116
+ rubygems_version: 2.4.5
129
117
  signing_key:
130
118
  specification_version: 4
131
119
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
132
120
  test_files: []
121
+ has_rdoc:
@@ -1,110 +0,0 @@
1
- module MiniMagick
2
- class CommandBuilder
3
- MOGRIFY_COMMANDS = %w(adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append attenuate authenticate auto-gamma auto-level auto-orient backdrop background bench bias black-point-compensation black-threshold blend blue-primary blue-shift blur border bordercolor borderwidth brightness-contrast cache caption cdl channel charcoal chop clamp clip clip-mask clip-path clone clut coalesce colorize colormap color-matrix colors colorspace combine comment compose composite compress contrast contrast-stretch convolve crop cycle debug decipher deconstruct define delay delete density depth descend deskew despeckle direction displace display dispose dissimilarity-threshold dissolve distort dither draw duplicate edge emboss encipher encoding endian enhance equalize evaluate evaluate-sequence extent extract family features fft fill filter flatten flip floodfill flop font foreground format frame function fuzz fx gamma gaussian-blur geometry gravity green-primary hald-clut help highlight-color iconGeometry iconic identify ift immutable implode insert intent interlace interpolate interline-spacing interword-spacing kerning label lat layers level level-colors limit linear-stretch linewidth liquid-rescale list log loop lowlight-color magnify map mask mattecolor median metric mode modulate monitor monochrome morph morphology mosaic motion-blur name negate noise normalize opaque ordered-dither orient page paint path pause pen perceptible ping pointsize polaroid poly posterize precision preview print process profile quality quantize quiet radial-blur raise random-threshold red-primary regard-warnings region remap remote render repage resample resize respect-parentheses reverse roll rotate sample sampling-factor scale scene screen seed segment selective-blur separate sepia-tone set shade shadow shared-memory sharpen shave shear sigmoidal-contrast silent size sketch smush snaps solarize sparse-color splice spread statistic stegano stereo stretch strip stroke strokewidth style subimage-search swap swirl synchronize taint text-font texture threshold thumbnail tile tile-offset tint title transform transparent transparent-color transpose transverse treedepth trim type undercolor unique-colors units unsharp update verbose version view vignette virtual-pixel visual watermark wave weight white-point white-threshold window window-group write)
4
- IMAGE_CREATION_OPERATORS = %w(canvas caption gradient label logo pattern plasma radial radient rose text tile xc)
5
-
6
- def initialize(tool, *options)
7
- @tool = tool
8
- @args = []
9
- options.each { |arg| push(arg) }
10
- end
11
-
12
- def command
13
- com = "#{@tool} #{args.join(' ')}".strip
14
- com = "#{MiniMagick.processor} #{com}" unless MiniMagick.mogrify?
15
-
16
- com = File.join MiniMagick.processor_path, com unless MiniMagick.processor_path.nil?
17
- com.strip
18
- end
19
-
20
- def args
21
- if !MiniMagick::Utilities.windows?
22
- @args.map(&:shellescape)
23
- else
24
- @args.map { |arg| Utilities.windows_escape(arg) }
25
- end
26
- end
27
-
28
- # Add each mogrify command in both underscore and dash format
29
- MOGRIFY_COMMANDS.each do |mogrify_command|
30
-
31
- # Example of what is generated here:
32
- #
33
- # def auto_orient(*options)
34
- # add_command("auto-orient", *options)
35
- # self
36
- # end
37
- # alias_method :"auto-orient", :auto_orient
38
-
39
- dashed_command = mogrify_command.to_s.gsub('_', '-')
40
- underscored_command = mogrify_command.to_s.gsub('-', '_')
41
-
42
- define_method(underscored_command) do |*options|
43
- options[1] = Utilities.windows_escape(options[1]) if mogrify_command == 'annotate'
44
- add_command(__method__.to_s.gsub('_', '-'), *options)
45
- self
46
- end
47
-
48
- alias_method dashed_command, underscored_command
49
- alias_method "mogrify_#{underscored_command}", underscored_command
50
- end
51
-
52
- def format(*options)
53
- fail Error, "You must call 'format' on the image object directly!"
54
- end
55
-
56
- IMAGE_CREATION_OPERATORS.each do |operator|
57
- define_method operator do |*options|
58
- add_creation_operator(__method__.to_s, *options)
59
- self
60
- end
61
-
62
- alias_method "operator_#{operator}", operator
63
- end
64
-
65
- (MOGRIFY_COMMANDS & IMAGE_CREATION_OPERATORS).each do |command_or_operator|
66
- define_method command_or_operator do |*options|
67
- if @tool == 'mogrify'
68
- method = self.method("mogrify_#{command_or_operator}")
69
- else
70
- method = self.method("operator_#{command_or_operator}")
71
- end
72
- method.call(*options)
73
- end
74
-
75
- end
76
-
77
- def +(*options)
78
- push(@args.pop.gsub(/^-/, '+'))
79
- if options.any?
80
- options.each do |o|
81
- push o
82
- end
83
- end
84
- end
85
-
86
- def add_command(command, *options)
87
- push "-#{command}"
88
- if options.any?
89
- options.each do |o|
90
- push o
91
- end
92
- end
93
- end
94
-
95
- def add_creation_operator(command, *options)
96
- creation_command = command
97
- if options.any?
98
- options.each do |option|
99
- creation_command << ":#{option}"
100
- end
101
- end
102
- push creation_command
103
- end
104
-
105
- def push(arg)
106
- @args << arg.to_s.strip
107
- end
108
- alias_method :<<, :push
109
- end
110
- end
@@ -1,4 +0,0 @@
1
- module MiniMagick
2
- class Error < RuntimeError; end
3
- class Invalid < StandardError; end
4
- end