mini_magick 3.8.1 → 4.0.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mini_gmagick.rb +2 -1
  3. data/lib/mini_magick/configuration.rb +136 -0
  4. data/lib/mini_magick/image/info.rb +122 -0
  5. data/lib/mini_magick/image.rb +384 -334
  6. data/lib/mini_magick/logger.rb +40 -0
  7. data/lib/mini_magick/shell.rb +48 -0
  8. data/lib/mini_magick/tool/animate.rb +14 -0
  9. data/lib/mini_magick/tool/compare.rb +14 -0
  10. data/lib/mini_magick/tool/composite.rb +14 -0
  11. data/lib/mini_magick/tool/conjure.rb +14 -0
  12. data/lib/mini_magick/tool/convert.rb +14 -0
  13. data/lib/mini_magick/tool/display.rb +14 -0
  14. data/lib/mini_magick/tool/identify.rb +14 -0
  15. data/lib/mini_magick/tool/import.rb +14 -0
  16. data/lib/mini_magick/tool/mogrify.rb +14 -0
  17. data/lib/mini_magick/tool/montage.rb +14 -0
  18. data/lib/mini_magick/tool/stream.rb +14 -0
  19. data/lib/mini_magick/tool.rb +250 -0
  20. data/lib/mini_magick/utilities.rb +23 -50
  21. data/lib/mini_magick/version.rb +4 -4
  22. data/lib/mini_magick.rb +43 -65
  23. metadata +21 -81
  24. data/lib/mini_magick/command_builder.rb +0 -94
  25. data/lib/mini_magick/errors.rb +0 -4
  26. data/spec/files/actually_a_gif.jpg +0 -0
  27. data/spec/files/animation.gif +0 -0
  28. data/spec/files/composited.jpg +0 -0
  29. data/spec/files/erroneous.jpg +0 -0
  30. data/spec/files/layers.psd +0 -0
  31. data/spec/files/leaves (spaced).tiff +0 -0
  32. data/spec/files/not_an_image.php +0 -1
  33. data/spec/files/png.png +0 -0
  34. data/spec/files/simple-minus.gif +0 -0
  35. data/spec/files/simple.gif +0 -0
  36. data/spec/files/trogdor.jpg +0 -0
  37. data/spec/files/trogdor_capitalized.JPG +0 -0
  38. data/spec/lib/mini_magick/command_builder_spec.rb +0 -153
  39. data/spec/lib/mini_magick/image_spec.rb +0 -499
  40. data/spec/lib/mini_magick_spec.rb +0 -63
  41. data/spec/spec_helper.rb +0 -29
data/lib/mini_magick.rb CHANGED
@@ -1,75 +1,53 @@
1
- require 'mini_magick/command_builder'
2
- require 'mini_magick/errors'
1
+ require 'mini_magick/configuration'
2
+ require 'mini_magick/tool'
3
3
  require 'mini_magick/image'
4
- require 'mini_magick/utilities'
5
4
 
6
5
  module MiniMagick
7
- @validate_on_create = true
8
- @validate_on_write = true
9
6
 
10
- class << self
11
- attr_accessor :processor
12
- attr_accessor :processor_path
13
- attr_accessor :timeout
14
- attr_accessor :debug
15
- attr_accessor :validate_on_create
16
- attr_accessor :validate_on_write
17
-
18
- ##
19
- # Tries to detect the current processor based if any of the processors
20
- # exist. Mogrify have precedence over gm by default.
21
- #
22
- # === Returns
23
- # * [Symbol] The detected procesor
24
- def processor
25
- @processor ||= [:mogrify, :gm].detect do |processor|
26
- MiniMagick::Utilities.which(processor.to_s)
27
- end
28
- 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
29
24
 
30
- ##
31
- # Discovers the imagemagick version based on mogrify's output.
32
- #
33
- # === Returns
34
- # * The imagemagick version
35
- def image_magick_version
36
- @@version ||= Gem::Version.create(`mogrify --version`.split(' ')[2].split('-').first)
37
- end
25
+ ##
26
+ # Checks whether the CLI used is ImageMagick.
27
+ #
28
+ # @return [Boolean]
29
+ def self.imagemagick?
30
+ cli == :imagemagick
31
+ end
38
32
 
39
- ##
40
- # The minimum allowed imagemagick version
41
- #
42
- # === Returns
43
- # * The minimum imagemagick version
44
- def minimum_image_magick_version
45
- @@minimum_version ||= Gem::Version.create('6.6.3')
46
- end
33
+ ##
34
+ # Checks whether the CLI used is GraphicsMagick.
35
+ #
36
+ # @return [Boolean]
37
+ def self.graphicsmagick?
38
+ cli == :graphicsmagick
39
+ end
47
40
 
48
- ##
49
- # Checks whether the imagemagick's version is valid
50
- #
51
- # === Returns
52
- # * [Boolean]
53
- def valid_version_installed?
54
- image_magick_version >= minimum_image_magick_version
55
- 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
56
49
 
57
- ##
58
- # Checks whether the current processory is mogrify.
59
- #
60
- # === Returns
61
- # * [Boolean]
62
- def mogrify?
63
- processor && processor.to_sym == :mogrify
64
- end
50
+ class Error < RuntimeError; end
51
+ class Invalid < StandardError; end
65
52
 
66
- ##
67
- # Checks whether the current processor is graphicsmagick.
68
- #
69
- # === Returns
70
- # * [Boolean]
71
- def gm?
72
- processor && processor.to_sym == :gm
73
- end
74
- end
75
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.1
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -12,22 +12,8 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-09-11 00:00:00.000000000 Z
15
+ date: 2014-11-23 00:00:00.000000000 Z
16
16
  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
17
  - !ruby/object:Gem::Dependency
32
18
  name: rake
33
19
  requirement: !ruby/object:Gem::Requirement
@@ -42,48 +28,20 @@ dependencies:
42
28
  - - ">="
43
29
  - !ruby/object:Gem::Version
44
30
  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
31
  - !ruby/object:Gem::Dependency
60
32
  name: rspec
61
33
  requirement: !ruby/object:Gem::Requirement
62
34
  requirements:
63
35
  - - "~>"
64
36
  - !ruby/object:Gem::Version
65
- version: 3.0.0
37
+ version: 3.1.0
66
38
  type: :development
67
39
  prerelease: false
68
40
  version_requirements: !ruby/object:Gem::Requirement
69
41
  requirements:
70
42
  - - "~>"
71
43
  - !ruby/object:Gem::Version
72
- version: 3.0.0
73
- - !ruby/object:Gem::Dependency
74
- name: mocha
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '0'
80
- type: :development
81
- prerelease: false
82
- version_requirements: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: '0'
44
+ version: 3.1.0
87
45
  description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
88
46
  email:
89
47
  - probablycorey@gmail.com
@@ -99,27 +57,25 @@ files:
99
57
  - Rakefile
100
58
  - lib/mini_gmagick.rb
101
59
  - lib/mini_magick.rb
102
- - lib/mini_magick/command_builder.rb
103
- - lib/mini_magick/errors.rb
60
+ - lib/mini_magick/configuration.rb
104
61
  - lib/mini_magick/image.rb
62
+ - lib/mini_magick/image/info.rb
63
+ - lib/mini_magick/logger.rb
64
+ - lib/mini_magick/shell.rb
65
+ - lib/mini_magick/tool.rb
66
+ - lib/mini_magick/tool/animate.rb
67
+ - lib/mini_magick/tool/compare.rb
68
+ - lib/mini_magick/tool/composite.rb
69
+ - lib/mini_magick/tool/conjure.rb
70
+ - lib/mini_magick/tool/convert.rb
71
+ - lib/mini_magick/tool/display.rb
72
+ - lib/mini_magick/tool/identify.rb
73
+ - lib/mini_magick/tool/import.rb
74
+ - lib/mini_magick/tool/mogrify.rb
75
+ - lib/mini_magick/tool/montage.rb
76
+ - lib/mini_magick/tool/stream.rb
105
77
  - lib/mini_magick/utilities.rb
106
78
  - lib/mini_magick/version.rb
107
- - spec/files/actually_a_gif.jpg
108
- - spec/files/animation.gif
109
- - spec/files/composited.jpg
110
- - spec/files/erroneous.jpg
111
- - spec/files/layers.psd
112
- - spec/files/leaves (spaced).tiff
113
- - spec/files/not_an_image.php
114
- - spec/files/png.png
115
- - spec/files/simple-minus.gif
116
- - spec/files/simple.gif
117
- - spec/files/trogdor.jpg
118
- - spec/files/trogdor_capitalized.JPG
119
- - spec/lib/mini_magick/command_builder_spec.rb
120
- - spec/lib/mini_magick/image_spec.rb
121
- - spec/lib/mini_magick_spec.rb
122
- - spec/spec_helper.rb
123
79
  homepage: https://github.com/minimagick/minimagick
124
80
  licenses:
125
81
  - MIT
@@ -145,20 +101,4 @@ rubygems_version: 2.2.2
145
101
  signing_key:
146
102
  specification_version: 4
147
103
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
148
- test_files:
149
- - spec/files/actually_a_gif.jpg
150
- - spec/files/animation.gif
151
- - spec/files/composited.jpg
152
- - spec/files/erroneous.jpg
153
- - spec/files/layers.psd
154
- - spec/files/leaves (spaced).tiff
155
- - spec/files/not_an_image.php
156
- - spec/files/png.png
157
- - spec/files/simple-minus.gif
158
- - spec/files/simple.gif
159
- - spec/files/trogdor.jpg
160
- - spec/files/trogdor_capitalized.JPG
161
- - spec/lib/mini_magick/command_builder_spec.rb
162
- - spec/lib/mini_magick/image_spec.rb
163
- - spec/lib/mini_magick_spec.rb
164
- - spec/spec_helper.rb
104
+ test_files: []
@@ -1,94 +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 if MiniMagick.processor_path
17
- com.strip
18
- end
19
-
20
- def args
21
- @args.map { |arg| Utilities.escape(arg) }
22
- end
23
-
24
- # Add each mogrify command in both underscore and dash format
25
- MOGRIFY_COMMANDS.each do |mogrify_command|
26
-
27
- # Example of what is generated here:
28
- #
29
- # def auto_orient(*options)
30
- # add_command("auto-orient", *options)
31
- # self
32
- # end
33
- # alias_method :"auto-orient", :auto_orient
34
-
35
- dashed_command = mogrify_command.to_s.gsub('_', '-')
36
- underscored_command = mogrify_command.to_s.gsub('-', '_')
37
-
38
- define_method(underscored_command) do |*options|
39
- options[1] = Utilities.windows_escape(options[1]) if mogrify_command == 'annotate'
40
- add_command(__method__.to_s.gsub('_', '-'), *options)
41
- self
42
- end
43
-
44
- alias_method dashed_command, underscored_command
45
- alias_method "mogrify_#{underscored_command}", underscored_command
46
- end
47
-
48
- def format(*options)
49
- fail Error, "You must call 'format' on the image object directly!"
50
- end
51
-
52
- IMAGE_CREATION_OPERATORS.each do |operator|
53
- define_method operator do |*options|
54
- add_creation_operator(__method__.to_s, *options)
55
- self
56
- end
57
-
58
- alias_method "operator_#{operator}", operator
59
- end
60
-
61
- (MOGRIFY_COMMANDS & IMAGE_CREATION_OPERATORS).each do |command_or_operator|
62
- define_method command_or_operator do |*options|
63
- if @tool == 'mogrify'
64
- method = self.method("mogrify_#{command_or_operator}")
65
- else
66
- method = self.method("operator_#{command_or_operator}")
67
- end
68
- method.call(*options)
69
- end
70
-
71
- end
72
-
73
- def +(*options)
74
- push(@args.pop.gsub(/\A-/, '+'))
75
- options.to_a.each { |option| push(option) }
76
- end
77
-
78
- def add_command(command, *options)
79
- push "-#{command}"
80
- options.to_a.each { |option| push(option) }
81
- end
82
-
83
- def add_creation_operator(command, *options)
84
- creation_command = command
85
- options.to_a.each { |option| creation_command << ":#{option}" }
86
- push creation_command
87
- end
88
-
89
- def push(arg)
90
- @args << arg.to_s.strip
91
- end
92
- alias_method :<<, :push
93
- end
94
- end
@@ -1,4 +0,0 @@
1
- module MiniMagick
2
- class Error < RuntimeError; end
3
- class Invalid < StandardError; end
4
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- <?php I am so not an image ?>
data/spec/files/png.png DELETED
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,153 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # All tests tagged as `ported` are ported from
4
- # testunit tests and are there for backwards compatibility
5
-
6
- MiniMagick.processor = :mogrify
7
-
8
- describe MiniMagick::CommandBuilder do
9
- before do
10
- @processor = MiniMagick.processor
11
- @processor_path = MiniMagick.processor_path
12
- end
13
-
14
- after do
15
- MiniMagick.processor_path = @processor_path
16
- MiniMagick.processor = @processor
17
- end
18
-
19
- describe 'ported from testunit', :ported => true do
20
- let(:builder) { described_class.new('test') }
21
-
22
- it 'builds a basic command' do
23
- builder.resize '30x40'
24
- expect(builder.args.join(' ')).to eq '-resize 30x40'
25
- end
26
-
27
- it 'builds a full command' do
28
- builder.resize '30x40'
29
- expect(builder.command).to eq 'test -resize 30x40'
30
- end
31
-
32
- describe 'windows only', :if => MiniMagick::Utilities.windows? do
33
- it 'builds a complicated command' do
34
- builder.resize '30x40'
35
- builder.alpha '1 3 4'
36
- builder.resize 'mome fingo'
37
- expect(builder.args.join(' ')).to eq '-resize 30x40 -alpha 1 3 4 -resize mome fingo'
38
- end
39
-
40
- it 'builds a command with multiple options and plus modifier' do
41
- builder.distort.+ 'srt', '0.6 20'
42
- expect(builder.args.join(' ')).to eq '+distort srt 0.6 20'
43
- end
44
-
45
- it 'sets a colorspace correctly' do
46
- builder.set 'colorspace RGB'
47
- expect(builder.command).to eq 'test -set colorspace RGB'
48
- end
49
- end
50
-
51
- describe 'not windows', :if => !MiniMagick::Utilities.windows? do
52
- it 'builds a complicated command' do
53
- builder.resize '30x40'
54
- builder.alpha '1 3 4'
55
- builder.resize 'mome fingo'
56
- expect(builder.args.join(' ')).to eq '-resize 30x40 -alpha 1\ 3\ 4 -resize mome\ fingo'
57
- end
58
-
59
- it 'sets a colorspace correctly' do
60
- builder.set 'colorspace RGB'
61
- expect(builder.command).to eq 'test -set colorspace\ RGB'
62
- end
63
-
64
- it 'builds a command with multiple options and plus modifier' do
65
- builder.distort.+ 'srt', '0.6 20'
66
- expect(builder.args.join(' ')).to eq '\+distort srt 0.6\ 20'
67
- end
68
- end
69
-
70
- describe 'common verbs between morgify and image creation operators' do
71
- context 'mogrify' do
72
- let(:builder) { described_class.new('mogrify') }
73
-
74
- it 'builds the command' do
75
- builder.caption 'caption_text'
76
- expect(builder.command).to eq 'mogrify -caption caption_text'
77
- end
78
- end
79
-
80
- context 'other' do
81
- it 'builds the command' do
82
- builder.caption 'caption_text'
83
- expect(builder.command).to eq 'test caption:caption_text'
84
- end
85
- end
86
- end
87
-
88
- it 'raises error when command is invalid' do
89
- expect {
90
- command = described_class.new('test', 'path')
91
- command.input 2
92
- }.to raise_error
93
- end
94
-
95
- it 'builds a dashed command' do
96
- builder.auto_orient
97
- expect(builder.args.join(' ')).to eq '-auto-orient'
98
- end
99
-
100
- it 'builds a dashed command via send' do
101
- builder.send('auto-orient')
102
- expect(builder.args.join(' ')).to eq '-auto-orient'
103
- end
104
-
105
- it 'builds a canvas command' do
106
- builder.canvas 'black'
107
- expect(builder.args.join(' ')).to eq 'canvas:black'
108
- end
109
-
110
- it 'sets a processor path correctly' do
111
- MiniMagick.processor_path = '/a/strange/path'
112
- builder.auto_orient
113
- expect(builder.command).to eq '/a/strange/path/test -auto-orient'
114
- end
115
-
116
- it 'builds a processor path with processor' do
117
- MiniMagick.processor_path = '/a/strange/path'
118
- MiniMagick.processor = 'processor'
119
- builder.auto_orient
120
- expect(builder.command).to eq '/a/strange/path/processor test -auto-orient'
121
- end
122
- end
123
-
124
- describe 'deprecated' do
125
- let(:builder) { described_class.new('test') }
126
- before { MiniMagick.processor = nil }
127
-
128
- it 'builds a full command' do
129
- builder.resize '30x40'
130
- expect(builder.command).to eq 'test -resize 30x40'
131
- end
132
-
133
- context 'windows only', :if => MiniMagick::Utilities.windows? do
134
- it 'sets a colorspace correctly' do
135
- builder.set 'colorspace RGB'
136
- expect(builder.command).to eq 'test -set colorspace RGB'
137
- end
138
- end
139
-
140
- context 'not windows', :if => !MiniMagick::Utilities.windows? do
141
- it 'sets a colorspace correctly' do
142
- builder.set 'colorspace RGB'
143
- expect(builder.command).to eq 'test -set colorspace\ RGB'
144
- end
145
- end
146
-
147
- it 'sets a processor path correctly' do
148
- MiniMagick.processor_path = '/a/strange/path'
149
- builder.auto_orient
150
- expect(builder.command).to eq '/a/strange/path/test -auto-orient'
151
- end
152
- end
153
- end