mini_magick 4.9.5 → 4.12.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: 66e2c6af6925e0ecc26c917f270ff575986489977416754ecc89db3bbab04dee
4
- data.tar.gz: cac982bbd12f543f637dce9a6fc8ed9e6c2139f7010d9da82f53a510ef2e2525
3
+ metadata.gz: 20aea50f08b4b5c234dc8167e3b8f344b3bb5e279e4d28857ce38d2acbdc0772
4
+ data.tar.gz: 513048f1e3315516fe592da1ecb3dec41f8e7a55e8165fe37db0720a297c5daa
5
5
  SHA512:
6
- metadata.gz: 03d841baabdc47d95a763010f113cfbc6d0acdf1ca8894e16c80bb86e307516b0f00da4c55617e5207360e4eb7bbb1e5268f5da62dabd4eb291da3d029354fdf
7
- data.tar.gz: 201f2187bedeb2db3157f15f611c026216b083b1e0174c67389a3a157976c0b887e211fc1e6bd2286736f27f04940f6c29586fd00d5079b6c2573e38a1739da4
6
+ metadata.gz: b5e8d72969c3649b4514a5b53fb5d228fb5db58bd9bdef0b7457838ed1289e62c8a6c0ec28cda9463fc16a159724d024a23043de5a377c2824f5bc9b148a627d
7
+ data.tar.gz: 28e78716378e97ba8c57758cb684b0428d734c1e5163f626a53b38f52c8f133db7fe0f041727c3a5ee200d241cdbd9409986caacc49746d361905c76a4bfed38
@@ -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.
@@ -53,6 +45,13 @@ module MiniMagick
53
45
  # @return [Logger]
54
46
  #
55
47
  attr_accessor :logger
48
+ ##
49
+ # Temporary directory used by MiniMagick, default is `Dir.tmpdir`, but
50
+ # you can override it.
51
+ #
52
+ # @return [String]
53
+ #
54
+ attr_accessor :tmpdir
56
55
 
57
56
  ##
58
57
  # If set to `true`, it will `identify` every newly created image, and raise
@@ -90,6 +89,7 @@ module MiniMagick
90
89
  attr_accessor :shell_api
91
90
 
92
91
  def self.extended(base)
92
+ base.tmpdir = Dir.tmpdir
93
93
  base.validate_on_create = true
94
94
  base.validate_on_write = true
95
95
  base.whiny = true
@@ -110,9 +110,9 @@ module MiniMagick
110
110
  end
111
111
 
112
112
  CLI_DETECTION = {
113
+ imagemagick7: "magick",
113
114
  imagemagick: "mogrify",
114
115
  graphicsmagick: "gm",
115
- imagemagick7: "magick",
116
116
  }
117
117
 
118
118
  # @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+\]$/
@@ -62,6 +62,16 @@ module MiniMagick
62
62
  raise MiniMagick::Invalid, "image data can't be read"
63
63
  end
64
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+(|\.\d+)([KMGTPEZY]{0,1})B$/)
71
+ end
72
+ raise TypeError
73
+ end
74
+
65
75
  def colorspace
66
76
  @info["colorspace"] ||= self["%r"]
67
77
  end
@@ -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.
@@ -102,7 +102,11 @@ module MiniMagick
102
102
  end
103
103
  ext.sub!(/:.*/, '') # hack for filenames or URLs that include a colon
104
104
 
105
- openable.open(options) { |file| read(file, ext) }
105
+ if openable.is_a?(URI::Generic)
106
+ openable.open(options) { |file| read(file, ext) }
107
+ else
108
+ openable.open(**options) { |file| read(file, ext) }
109
+ end
106
110
  end
107
111
 
108
112
  ##
@@ -336,13 +340,18 @@ module MiniMagick
336
340
  #
337
341
  # 1) one for each row of pixels
338
342
  # 2) one for each column of pixels
339
- # 3) three elements in the range 0-255, one for each of the RGB color channels
343
+ # 3) three or four elements in the range 0-255, one for each of the RGB(A) color channels
340
344
  #
341
345
  # @example
342
346
  # img = MiniMagick::Image.open 'image.jpg'
343
347
  # pixels = img.get_pixels
344
348
  # pixels[3][2][1] # the green channel value from the 4th-row, 3rd-column pixel
345
349
  #
350
+ # @example
351
+ # img = MiniMagick::Image.open 'image.jpg'
352
+ # pixels = img.get_pixels("RGBA")
353
+ # pixels[3][2][3] # the alpha channel value from the 4th-row, 3rd-column pixel
354
+ #
346
355
  # It can also be called after applying transformations:
347
356
  #
348
357
  # @example
@@ -353,19 +362,22 @@ module MiniMagick
353
362
  #
354
363
  # In this example, all pixels in pix should now have equal R, G, and B values.
355
364
  #
365
+ # @param map [String] A code for the mapping of the pixel data. Must be either
366
+ # 'RGB' or 'RGBA'. Default to 'RGB'
356
367
  # @return [Array] Matrix of each color of each pixel
357
- def get_pixels
368
+ def get_pixels(map="RGB")
369
+ raise ArgumentError, "Invalid map value" unless ["RGB", "RGBA"].include?(map)
358
370
  convert = MiniMagick::Tool::Convert.new
359
371
  convert << path
360
372
  convert.depth(8)
361
- convert << "RGB:-"
373
+ convert << "#{map}:-"
362
374
 
363
375
  # Do not use `convert.call` here. We need the whole binary (unstripped) output here.
364
376
  shell = MiniMagick::Shell.new
365
377
  output, * = shell.run(convert.command)
366
378
 
367
379
  pixels_array = output.unpack("C*")
368
- pixels = pixels_array.each_slice(3).each_slice(width).to_a
380
+ pixels = pixels_array.each_slice(map.length).each_slice(width).to_a
369
381
 
370
382
  # deallocate large intermediary objects
371
383
  output.clear
@@ -374,6 +386,23 @@ module MiniMagick
374
386
  pixels
375
387
  end
376
388
 
389
+ ##
390
+ # This is used to create image from pixels. This might be required if you
391
+ # create pixels for some image processing reasons and you want to form
392
+ # image from those pixels.
393
+ #
394
+ # *DANGER*: This operation can be very expensive. Please try to use with
395
+ # caution.
396
+ #
397
+ # @example
398
+ # # It is given in readme.md file
399
+ ##
400
+ def self.get_image_from_pixels(pixels, dimension, map, depth, mime_type)
401
+ pixels = pixels.flatten
402
+ blob = pixels.pack('C*')
403
+ import_pixels(blob, *dimension, depth, map, mime_type)
404
+ end
405
+
377
406
  ##
378
407
  # This is used to change the format of the image. That is, from "tiff to
379
408
  # jpg" or something like that. Once you run it, the instance is pointing to
@@ -432,6 +461,9 @@ module MiniMagick
432
461
  @info.clear
433
462
 
434
463
  self
464
+ rescue MiniMagick::Invalid, MiniMagick::Error => e
465
+ new_tempfile.unlink if new_tempfile && @tempfile != new_tempfile
466
+ raise e
435
467
  end
436
468
 
437
469
  ##
@@ -583,5 +615,31 @@ module MiniMagick
583
615
  def layer?
584
616
  path =~ /\[\d+\]$/
585
617
  end
618
+
619
+ ##
620
+ # Compares if image width
621
+ # is greater than height
622
+ # ============
623
+ # | |
624
+ # | |
625
+ # ============
626
+ # @return [Boolean]
627
+ def landscape?
628
+ width > height
629
+ end
630
+
631
+ ##
632
+ # Compares if image height
633
+ # is greater than width
634
+ # ======
635
+ # | |
636
+ # | |
637
+ # | |
638
+ # | |
639
+ # ======
640
+ # @return [Boolean]
641
+ def portrait?
642
+ height > width
643
+ end
586
644
  end
587
645
  end
@@ -14,7 +14,7 @@ module MiniMagick
14
14
  stdout, stderr, status = execute(command, stdin: options[:stdin])
15
15
 
16
16
  if status != 0 && options.fetch(:whiny, MiniMagick.whiny)
17
- fail MiniMagick::Error, "`#{command.join(" ")}` failed with error:\n#{stderr}"
17
+ fail MiniMagick::Error, "`#{command.join(" ")}` failed with status: #{status} and error:\n#{stderr}"
18
18
  end
19
19
 
20
20
  $stderr.print(stderr) unless options[:stderr] == false
@@ -25,7 +25,7 @@ module MiniMagick
25
25
  def execute(command, options = {})
26
26
  stdout, stderr, status =
27
27
  log(command.join(" ")) do
28
- send("execute_#{MiniMagick.shell_api.gsub("-", "_")}", command, options)
28
+ send("execute_#{MiniMagick.shell_api.tr("-", "_")}", command, options)
29
29
  end
30
30
 
31
31
  [stdout, stderr, status.exitstatus]
@@ -50,9 +50,7 @@ module MiniMagick
50
50
  end
51
51
  in_w.close
52
52
 
53
- begin
54
- Timeout.timeout(MiniMagick.timeout) { thread.join }
55
- rescue Timeout::Error
53
+ unless thread.join(MiniMagick.timeout)
56
54
  Process.kill("TERM", thread.pid) rescue nil
57
55
  Process.waitpid(thread.pid) rescue nil
58
56
  raise Timeout::Error, "MiniMagick command timed out: #{command}"
@@ -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,12 +235,13 @@ 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"
233
242
  #
234
243
  CREATION_OPERATORS.each do |operator|
235
- define_method(operator.gsub('-', '_')) do |value = nil|
244
+ define_method(operator.tr('-', '_')) do |value = nil|
236
245
  self << "#{operator}:#{value}"
237
246
  self
238
247
  end
@@ -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('_', '-')}"
@@ -24,7 +24,7 @@ module MiniMagick
24
24
  end
25
25
 
26
26
  def tempfile(extension)
27
- Tempfile.new(["mini_magick", extension]).tap do |tempfile|
27
+ Tempfile.new(["mini_magick", extension], MiniMagick.tmpdir).tap do |tempfile|
28
28
  tempfile.binmode
29
29
  yield tempfile if block_given?
30
30
  tempfile.close
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 9
12
- TINY = 5
11
+ MINOR = 12
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.5
4
+ version: 4.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -10,10 +10,10 @@ authors:
10
10
  - James Miller
11
11
  - Thiago Fernandes Massa
12
12
  - Janko Marohnić
13
- autorequire:
13
+ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-07-18 00:00:00.000000000 Z
16
+ date: 2022-12-07 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake
@@ -139,7 +139,7 @@ homepage: https://github.com/minimagick/minimagick
139
139
  licenses:
140
140
  - MIT
141
141
  metadata: {}
142
- post_install_message:
142
+ post_install_message:
143
143
  rdoc_options: []
144
144
  require_paths:
145
145
  - lib
@@ -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,8 +155,8 @@ 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
159
- signing_key:
158
+ rubygems_version: 3.3.3
159
+ signing_key:
160
160
  specification_version: 4
161
161
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
162
162
  test_files: []