mini_magick 4.9.4 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ab4ce03957b9a0f941f9bd2c34a5dcab63faffac5143eb6e7c90d7d860b57c5
4
- data.tar.gz: 7bd78f0c862f1ca72b34e3c6fc4d14297adfa9dd6bc36218a35ef68c235320b5
3
+ metadata.gz: f97cb0365a2a45cdb41c9091a4339fdd75a37cdb041c454cab800fd9464f5c0f
4
+ data.tar.gz: b5f97721ee2657631def0e8c498f257639e126a3ad745688356ae5a15ff5de9f
5
5
  SHA512:
6
- metadata.gz: 16c4bfa3744a2bea117bff0118afcbf89fac2f3d9e92c5c8af2b095f6c1381c1d000bede5086ccffd72ecca8152845cde11a5ff762186bd90793ee5d83e03a77
7
- data.tar.gz: fe593ad2a7bfd4b6f2d9892533fd5347046e7dfb6cfd8e3bc6049cb1ae7686f5af60c23f33254175bca4728a58bdeeab2b9bfb873ebd94c46f14e68e086f002f
6
+ metadata.gz: 5339cf648a6cdc78f5a115e03ab77ec3f61bd83de5fcea0638ccb354e9b03b4c29e59b31e6681da9e1a238b2bee73b2a460ed5db0989eca90c097f29a9b0ebb5
7
+ data.tar.gz: 53b55f439ac4172e68e82c20e67a357160303fc3c382c0d7bb4bfeb4ba1e3e469b95ff89c517ab15f0c67436ab1c831fee5d7e88d0e981876cbc059b5c7dfad6
@@ -4,14 +4,6 @@ require 'logger'
4
4
  module MiniMagick
5
5
  module Configuration
6
6
 
7
- ##
8
- # Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
9
- # [GraphicsMagick](http://www.graphicsmagick.org).
10
- #
11
- # @return [Symbol] `:imagemagick`, `:imagemagick7`, or `:graphicsmagick`
12
- #
13
- attr_accessor :cli
14
-
15
7
  ##
16
8
  # If you don't have the CLI tools in your PATH, you can set the path to the
17
9
  # executables.
@@ -110,9 +102,9 @@ module MiniMagick
110
102
  end
111
103
 
112
104
  CLI_DETECTION = {
105
+ imagemagick7: "magick",
113
106
  imagemagick: "mogrify",
114
107
  graphicsmagick: "gm",
115
- imagemagick7: "magick",
116
108
  }
117
109
 
118
110
  # @private (for backwards compatibility)
@@ -42,7 +42,7 @@ module MiniMagick
42
42
 
43
43
  def cheap_info(value)
44
44
  @info.fetch(value) do
45
- format, width, height, size = self["%m %w %h %b"].split(" ")
45
+ format, width, height, size = parse_warnings(self["%m %w %h %b"]).split(" ")
46
46
 
47
47
  path = @path
48
48
  path = path.match(/\[\d+\]$/).pre_match if path =~ /\[\d+\]$/
@@ -61,6 +61,16 @@ module MiniMagick
61
61
  rescue ArgumentError, TypeError
62
62
  raise MiniMagick::Invalid, "image data can't be read"
63
63
  end
64
+
65
+ def parse_warnings(raw_info)
66
+ return raw_info unless raw_info.split("\n").size > 1
67
+
68
+ raw_info.split("\n").each do |line|
69
+ # must match "%m %w %h %b"
70
+ return line if line.match? /^[A-Z]+ \d+ \d+ \d+B$/
71
+ end
72
+ raise TypeError
73
+ end
64
74
 
65
75
  def colorspace
66
76
  @info["colorspace"] ||= self["%r"]
@@ -15,7 +15,7 @@ module MiniMagick
15
15
  # methods.
16
16
  #
17
17
  # Use this to pass in a stream object. Must respond to #read(size) or be a
18
- # binary string object (BLOBBBB)
18
+ # binary string object (BLOB)
19
19
  #
20
20
  # Probably easier to use the {.open} method if you want to open a file or a
21
21
  # URL.
@@ -82,15 +82,30 @@ module MiniMagick
82
82
  def self.open(path_or_url, ext = nil, options = {})
83
83
  options, ext = ext, nil if ext.is_a?(Hash)
84
84
 
85
- uri = URI(path_or_url.to_s)
85
+ # Don't use Kernel#open, but reuse its logic
86
+ openable =
87
+ if path_or_url.respond_to?(:open)
88
+ path_or_url
89
+ elsif path_or_url.respond_to?(:to_str) &&
90
+ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ path_or_url &&
91
+ (uri = URI.parse(path_or_url)).respond_to?(:open)
92
+ uri
93
+ else
94
+ options = { binmode: true }.merge(options)
95
+ Pathname(path_or_url)
96
+ end
86
97
 
87
- ext ||= File.extname(uri.path)
98
+ if openable.is_a?(URI::Generic)
99
+ ext ||= File.extname(openable.path)
100
+ else
101
+ ext ||= File.extname(openable.to_s)
102
+ end
88
103
  ext.sub!(/:.*/, '') # hack for filenames or URLs that include a colon
89
104
 
90
- if uri.is_a?(URI::HTTP) || uri.is_a?(URI::FTP)
91
- uri.open(options) { |file| read(file, ext) }
105
+ if openable.is_a?(URI::Generic)
106
+ openable.open(options) { |file| read(file, ext) }
92
107
  else
93
- File.open(uri.to_s, "rb", options) { |file| read(file, ext) }
108
+ openable.open(**options) { |file| read(file, ext) }
94
109
  end
95
110
  end
96
111
 
@@ -363,6 +378,23 @@ module MiniMagick
363
378
  pixels
364
379
  end
365
380
 
381
+ ##
382
+ # This is used to create image from pixels. This might be required if you
383
+ # create pixels for some image processing reasons and you want to form
384
+ # image from those pixels.
385
+ #
386
+ # *DANGER*: This operation can be very expensive. Please try to use with
387
+ # caution.
388
+ #
389
+ # @example
390
+ # # It is given in readme.md file
391
+ ##
392
+ def self.get_image_from_pixels(pixels, dimension, map, depth, mime_type)
393
+ pixels = pixels.flatten
394
+ blob = pixels.pack('C*')
395
+ import_pixels(blob, *dimension, depth, map, mime_type)
396
+ end
397
+
366
398
  ##
367
399
  # This is used to change the format of the image. That is, from "tiff to
368
400
  # jpg" or something like that. Once you run it, the instance is pointing to
@@ -572,5 +604,31 @@ module MiniMagick
572
604
  def layer?
573
605
  path =~ /\[\d+\]$/
574
606
  end
607
+
608
+ ##
609
+ # Compares if image width
610
+ # is greater than height
611
+ # ============
612
+ # | |
613
+ # | |
614
+ # ============
615
+ # @return [Boolean]
616
+ def landscape?
617
+ width > height
618
+ end
619
+
620
+ ##
621
+ # Compares if image height
622
+ # is greater than width
623
+ # ======
624
+ # | |
625
+ # | |
626
+ # | |
627
+ # | |
628
+ # ======
629
+ # @return [Boolean]
630
+ def portrait?
631
+ height > width
632
+ end
575
633
  end
576
634
  end
@@ -44,8 +44,10 @@ module MiniMagick
44
44
  # @private
45
45
  attr_reader :name, :args
46
46
 
47
- # @param whiny [Boolean] Whether to raise errors on exit codes different
48
- # than 0.
47
+ # @param name [String]
48
+ # @param options [Hash]
49
+ # @option options [Boolean] :whiny Whether to raise errors on non-zero
50
+ # exit codes.
49
51
  # @example
50
52
  # MiniMagick::Tool::Identify.new(whiny: false) do |identify|
51
53
  # identify.help # returns exit status 1, which would otherwise throw an error
@@ -190,9 +192,15 @@ module MiniMagick
190
192
  # end
191
193
  # # executes `convert wand.gif \( wizard.gif -rotate 30 \) +append images.gif`
192
194
  #
193
- def stack
195
+ def stack(*args)
194
196
  self << "("
195
- yield self
197
+ args.each do |value|
198
+ case value
199
+ when Hash then value.each { |key, value| send(key, *value) }
200
+ when String then self << value
201
+ end
202
+ end
203
+ yield self if block_given?
196
204
  self << ")"
197
205
  end
198
206
 
@@ -227,6 +235,7 @@ module MiniMagick
227
235
  ##
228
236
  # Define creator operator methods
229
237
  #
238
+ # @example
230
239
  # mogrify = MiniMagick::Tool.new("mogrify")
231
240
  # mogrify.canvas("khaki")
232
241
  # mogrify.command.join(" ") #=> "mogrify canvas:khaki"
@@ -251,10 +260,11 @@ module MiniMagick
251
260
  ##
252
261
  # Any undefined method will be transformed into a CLI option
253
262
  #
263
+ # @example
254
264
  # mogrify = MiniMagick::Tool.new("mogrify")
255
265
  # mogrify.adaptive_blur("...")
256
266
  # mogrify.foo_bar
257
- # mogrify.command.join(" ") "mogrify -adaptive-blur ... -foo-bar"
267
+ # mogrify.command.join(" ") # => "mogrify -adaptive-blur ... -foo-bar"
258
268
  #
259
269
  def method_missing(name, *args)
260
270
  option = "-#{name.to_s.tr('_', '-')}"
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 9
12
- TINY = 4
11
+ MINOR = 11
12
+ TINY = 0
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
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: 4.9.4
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-07-11 00:00:00.000000000 Z
16
+ date: 2020-11-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
- version: '0'
150
+ version: '2.0'
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - ">="
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements:
157
157
  - You must have ImageMagick or GraphicsMagick installed
158
- rubygems_version: 3.0.3
158
+ rubygems_version: 3.1.4
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick