mini_magick 4.11.0 → 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: f97cb0365a2a45cdb41c9091a4339fdd75a37cdb041c454cab800fd9464f5c0f
4
- data.tar.gz: b5f97721ee2657631def0e8c498f257639e126a3ad745688356ae5a15ff5de9f
3
+ metadata.gz: 20aea50f08b4b5c234dc8167e3b8f344b3bb5e279e4d28857ce38d2acbdc0772
4
+ data.tar.gz: 513048f1e3315516fe592da1ecb3dec41f8e7a55e8165fe37db0720a297c5daa
5
5
  SHA512:
6
- metadata.gz: 5339cf648a6cdc78f5a115e03ab77ec3f61bd83de5fcea0638ccb354e9b03b4c29e59b31e6681da9e1a238b2bee73b2a460ed5db0989eca90c097f29a9b0ebb5
7
- data.tar.gz: 53b55f439ac4172e68e82c20e67a357160303fc3c382c0d7bb4bfeb4ba1e3e469b95ff89c517ab15f0c67436ab1c831fee5d7e88d0e981876cbc059b5c7dfad6
6
+ metadata.gz: b5e8d72969c3649b4514a5b53fb5d228fb5db58bd9bdef0b7457838ed1289e62c8a6c0ec28cda9463fc16a159724d024a23043de5a377c2824f5bc9b148a627d
7
+ data.tar.gz: 28e78716378e97ba8c57758cb684b0428d734c1e5163f626a53b38f52c8f133db7fe0f041727c3a5ee200d241cdbd9409986caacc49746d361905c76a4bfed38
@@ -45,6 +45,13 @@ module MiniMagick
45
45
  # @return [Logger]
46
46
  #
47
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
48
55
 
49
56
  ##
50
57
  # If set to `true`, it will `identify` every newly created image, and raise
@@ -82,6 +89,7 @@ module MiniMagick
82
89
  attr_accessor :shell_api
83
90
 
84
91
  def self.extended(base)
92
+ base.tmpdir = Dir.tmpdir
85
93
  base.validate_on_create = true
86
94
  base.validate_on_write = true
87
95
  base.whiny = true
@@ -61,13 +61,13 @@ module MiniMagick
61
61
  rescue ArgumentError, TypeError
62
62
  raise MiniMagick::Invalid, "image data can't be read"
63
63
  end
64
-
64
+
65
65
  def parse_warnings(raw_info)
66
66
  return raw_info unless raw_info.split("\n").size > 1
67
67
 
68
68
  raw_info.split("\n").each do |line|
69
69
  # must match "%m %w %h %b"
70
- return line if line.match? /^[A-Z]+ \d+ \d+ \d+B$/
70
+ return line if line.match?(/^[A-Z]+ \d+ \d+ \d+(|\.\d+)([KMGTPEZY]{0,1})B$/)
71
71
  end
72
72
  raise TypeError
73
73
  end
@@ -340,13 +340,18 @@ module MiniMagick
340
340
  #
341
341
  # 1) one for each row of pixels
342
342
  # 2) one for each column of pixels
343
- # 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
344
344
  #
345
345
  # @example
346
346
  # img = MiniMagick::Image.open 'image.jpg'
347
347
  # pixels = img.get_pixels
348
348
  # pixels[3][2][1] # the green channel value from the 4th-row, 3rd-column pixel
349
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
+ #
350
355
  # It can also be called after applying transformations:
351
356
  #
352
357
  # @example
@@ -357,19 +362,22 @@ module MiniMagick
357
362
  #
358
363
  # In this example, all pixels in pix should now have equal R, G, and B values.
359
364
  #
365
+ # @param map [String] A code for the mapping of the pixel data. Must be either
366
+ # 'RGB' or 'RGBA'. Default to 'RGB'
360
367
  # @return [Array] Matrix of each color of each pixel
361
- def get_pixels
368
+ def get_pixels(map="RGB")
369
+ raise ArgumentError, "Invalid map value" unless ["RGB", "RGBA"].include?(map)
362
370
  convert = MiniMagick::Tool::Convert.new
363
371
  convert << path
364
372
  convert.depth(8)
365
- convert << "RGB:-"
373
+ convert << "#{map}:-"
366
374
 
367
375
  # Do not use `convert.call` here. We need the whole binary (unstripped) output here.
368
376
  shell = MiniMagick::Shell.new
369
377
  output, * = shell.run(convert.command)
370
378
 
371
379
  pixels_array = output.unpack("C*")
372
- pixels = pixels_array.each_slice(3).each_slice(width).to_a
380
+ pixels = pixels_array.each_slice(map.length).each_slice(width).to_a
373
381
 
374
382
  # deallocate large intermediary objects
375
383
  output.clear
@@ -453,6 +461,9 @@ module MiniMagick
453
461
  @info.clear
454
462
 
455
463
  self
464
+ rescue MiniMagick::Invalid, MiniMagick::Error => e
465
+ new_tempfile.unlink if new_tempfile && @tempfile != new_tempfile
466
+ raise e
456
467
  end
457
468
 
458
469
  ##
@@ -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}"
@@ -241,7 +241,7 @@ module MiniMagick
241
241
  # mogrify.command.join(" ") #=> "mogrify canvas:khaki"
242
242
  #
243
243
  CREATION_OPERATORS.each do |operator|
244
- define_method(operator.gsub('-', '_')) do |value = nil|
244
+ define_method(operator.tr('-', '_')) do |value = nil|
245
245
  self << "#{operator}:#{value}"
246
246
  self
247
247
  end
@@ -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,7 +8,7 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 11
11
+ MINOR = 12
12
12
  TINY = 0
13
13
  PRE = nil
14
14
 
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.11.0
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: 2020-11-06 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
@@ -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.1.4
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: []