mini_magick 3.8.1 → 4.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/lib/mini_gmagick.rb +1 -0
  3. data/lib/mini_magick/configuration.rb +198 -0
  4. data/lib/mini_magick/image/info.rb +192 -0
  5. data/lib/mini_magick/image.rb +456 -341
  6. data/lib/mini_magick/shell.rb +81 -0
  7. data/lib/mini_magick/tool/animate.rb +14 -0
  8. data/lib/mini_magick/tool/compare.rb +14 -0
  9. data/lib/mini_magick/tool/composite.rb +14 -0
  10. data/lib/mini_magick/tool/conjure.rb +14 -0
  11. data/lib/mini_magick/tool/convert.rb +14 -0
  12. data/lib/mini_magick/tool/display.rb +14 -0
  13. data/lib/mini_magick/tool/identify.rb +14 -0
  14. data/lib/mini_magick/tool/import.rb +14 -0
  15. data/lib/mini_magick/tool/magick.rb +14 -0
  16. data/lib/mini_magick/tool/mogrify.rb +14 -0
  17. data/lib/mini_magick/tool/mogrify_restricted.rb +15 -0
  18. data/lib/mini_magick/tool/montage.rb +14 -0
  19. data/lib/mini_magick/tool/stream.rb +14 -0
  20. data/lib/mini_magick/tool.rb +297 -0
  21. data/lib/mini_magick/utilities.rb +23 -50
  22. data/lib/mini_magick/version.rb +5 -5
  23. data/lib/mini_magick.rb +54 -65
  24. metadata +49 -51
  25. data/lib/mini_magick/command_builder.rb +0 -94
  26. data/lib/mini_magick/errors.rb +0 -4
  27. data/spec/files/actually_a_gif.jpg +0 -0
  28. data/spec/files/animation.gif +0 -0
  29. data/spec/files/composited.jpg +0 -0
  30. data/spec/files/erroneous.jpg +0 -0
  31. data/spec/files/layers.psd +0 -0
  32. data/spec/files/leaves (spaced).tiff +0 -0
  33. data/spec/files/not_an_image.php +0 -1
  34. data/spec/files/png.png +0 -0
  35. data/spec/files/simple-minus.gif +0 -0
  36. data/spec/files/simple.gif +0 -0
  37. data/spec/files/trogdor.jpg +0 -0
  38. data/spec/files/trogdor_capitalized.JPG +0 -0
  39. data/spec/lib/mini_magick/command_builder_spec.rb +0 -153
  40. data/spec/lib/mini_magick/image_spec.rb +0 -499
  41. data/spec/lib/mini_magick_spec.rb +0 -63
  42. data/spec/spec_helper.rb +0 -29
data/lib/mini_magick.rb CHANGED
@@ -1,75 +1,64 @@
1
- require 'mini_magick/command_builder'
2
- require 'mini_magick/errors'
3
- require 'mini_magick/image'
4
- require 'mini_magick/utilities'
1
+ require 'mini_magick/version'
2
+ require 'mini_magick/configuration'
5
3
 
6
4
  module MiniMagick
7
- @validate_on_create = true
8
- @validate_on_write = true
9
-
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
5
 
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
6
+ extend MiniMagick::Configuration
29
7
 
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
8
+ ##
9
+ # You might want to execute only certain blocks of processing with a
10
+ # different CLI, because for example that CLI does that particular thing
11
+ # faster. After the block CLI resets to its previous value.
12
+ #
13
+ # @example
14
+ # MiniMagick.with_cli :graphicsmagick do
15
+ # # operations that are better done with GraphicsMagick
16
+ # end
17
+ def self.with_cli(cli)
18
+ old_cli = self.cli
19
+ self.cli = cli
20
+ yield
21
+ ensure
22
+ self.cli = old_cli
23
+ end
38
24
 
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
25
+ ##
26
+ # Checks whether the CLI used is ImageMagick.
27
+ #
28
+ # @return [Boolean]
29
+ def self.imagemagick?
30
+ cli == :imagemagick
31
+ end
47
32
 
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
33
+ ##
34
+ # Checks whether the CLI used is ImageMagick 7.
35
+ #
36
+ # @return [Boolean]
37
+ def self.imagemagick7?
38
+ cli == :imagemagick7
39
+ end
56
40
 
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
41
+ ##
42
+ # Checks whether the CLI used is GraphicsMagick.
43
+ #
44
+ # @return [Boolean]
45
+ def self.graphicsmagick?
46
+ cli == :graphicsmagick
47
+ end
65
48
 
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
49
+ ##
50
+ # Returns ImageMagick's/GraphicsMagick's version.
51
+ #
52
+ # @return [String]
53
+ def self.cli_version
54
+ output = MiniMagick::Tool::Identify.new(&:version)
55
+ output[/\d+\.\d+\.\d+(-\d+)?/]
74
56
  end
57
+
58
+ class Error < RuntimeError; end
59
+ class Invalid < StandardError; end
60
+
75
61
  end
62
+
63
+ require 'mini_magick/tool'
64
+ require 'mini_magick/image'
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.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -9,27 +9,42 @@ 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-09-11 00:00:00.000000000 Z
16
+ date: 2019-07-11 00:00:00.000000000 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
- name: subexec
19
+ name: rake
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
19
34
  requirement: !ruby/object:Gem::Requirement
20
35
  requirements:
21
36
  - - "~>"
22
37
  - !ruby/object:Gem::Version
23
- version: 0.2.1
24
- type: :runtime
38
+ version: 3.5.0
39
+ type: :development
25
40
  prerelease: false
26
41
  version_requirements: !ruby/object:Gem::Requirement
27
42
  requirements:
28
43
  - - "~>"
29
44
  - !ruby/object:Gem::Version
30
- version: 0.2.1
45
+ version: 3.5.0
31
46
  - !ruby/object:Gem::Dependency
32
- name: rake
47
+ name: guard
33
48
  requirement: !ruby/object:Gem::Requirement
34
49
  requirements:
35
50
  - - ">="
@@ -43,7 +58,7 @@ dependencies:
43
58
  - !ruby/object:Gem::Version
44
59
  version: '0'
45
60
  - !ruby/object:Gem::Dependency
46
- name: test-unit
61
+ name: guard-rspec
47
62
  requirement: !ruby/object:Gem::Requirement
48
63
  requirements:
49
64
  - - ">="
@@ -57,21 +72,21 @@ dependencies:
57
72
  - !ruby/object:Gem::Version
58
73
  version: '0'
59
74
  - !ruby/object:Gem::Dependency
60
- name: rspec
75
+ name: posix-spawn
61
76
  requirement: !ruby/object:Gem::Requirement
62
77
  requirements:
63
- - - "~>"
78
+ - - ">="
64
79
  - !ruby/object:Gem::Version
65
- version: 3.0.0
80
+ version: '0'
66
81
  type: :development
67
82
  prerelease: false
68
83
  version_requirements: !ruby/object:Gem::Requirement
69
84
  requirements:
70
- - - "~>"
85
+ - - ">="
71
86
  - !ruby/object:Gem::Version
72
- version: 3.0.0
87
+ version: '0'
73
88
  - !ruby/object:Gem::Dependency
74
- name: mocha
89
+ name: webmock
75
90
  requirement: !ruby/object:Gem::Requirement
76
91
  requirements:
77
92
  - - ">="
@@ -91,6 +106,7 @@ email:
91
106
  - peter@nulayer.com
92
107
  - bensie@gmail.com
93
108
  - thiagown@gmail.com
109
+ - janko.marohnic@gmail.com
94
110
  executables: []
95
111
  extensions: []
96
112
  extra_rdoc_files: []
@@ -99,27 +115,26 @@ files:
99
115
  - Rakefile
100
116
  - lib/mini_gmagick.rb
101
117
  - lib/mini_magick.rb
102
- - lib/mini_magick/command_builder.rb
103
- - lib/mini_magick/errors.rb
118
+ - lib/mini_magick/configuration.rb
104
119
  - lib/mini_magick/image.rb
120
+ - lib/mini_magick/image/info.rb
121
+ - lib/mini_magick/shell.rb
122
+ - lib/mini_magick/tool.rb
123
+ - lib/mini_magick/tool/animate.rb
124
+ - lib/mini_magick/tool/compare.rb
125
+ - lib/mini_magick/tool/composite.rb
126
+ - lib/mini_magick/tool/conjure.rb
127
+ - lib/mini_magick/tool/convert.rb
128
+ - lib/mini_magick/tool/display.rb
129
+ - lib/mini_magick/tool/identify.rb
130
+ - lib/mini_magick/tool/import.rb
131
+ - lib/mini_magick/tool/magick.rb
132
+ - lib/mini_magick/tool/mogrify.rb
133
+ - lib/mini_magick/tool/mogrify_restricted.rb
134
+ - lib/mini_magick/tool/montage.rb
135
+ - lib/mini_magick/tool/stream.rb
105
136
  - lib/mini_magick/utilities.rb
106
137
  - 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
138
  homepage: https://github.com/minimagick/minimagick
124
139
  licenses:
125
140
  - MIT
@@ -140,25 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
155
  version: '0'
141
156
  requirements:
142
157
  - You must have ImageMagick or GraphicsMagick installed
143
- rubyforge_project:
144
- rubygems_version: 2.2.2
158
+ rubygems_version: 3.0.3
145
159
  signing_key:
146
160
  specification_version: 4
147
161
  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
162
+ 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