mini_magick 4.10.1 → 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: 29b57b7ad13279ad3a6cdef274c7b9cc6efd5c509db5f6bd826e6affe6364081
4
- data.tar.gz: e958f807b9d779f94e502786510b656948d3ecbb9f89c2539ff0aa11afd0079e
3
+ metadata.gz: 20aea50f08b4b5c234dc8167e3b8f344b3bb5e279e4d28857ce38d2acbdc0772
4
+ data.tar.gz: 513048f1e3315516fe592da1ecb3dec41f8e7a55e8165fe37db0720a297c5daa
5
5
  SHA512:
6
- metadata.gz: 71843702fea5e44a8ef160c03af2319b6cce43d8191201056fff1a32e9297c3045e0c2cb15a6611243c4ab0ed9f8883a4f1669ef570c8da659e1c1a17d3e922f
7
- data.tar.gz: 5cb059a1319aa29750ec2e5e46d04b5b9256b2ca4896a72f28ca94594df573a16d607f35558fc49b00f9839b4e8553df94788e24842f43b18aaa10d9ec39c7e7
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
@@ -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.
@@ -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
@@ -378,6 +386,23 @@ module MiniMagick
378
386
  pixels
379
387
  end
380
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
+
381
406
  ##
382
407
  # This is used to change the format of the image. That is, from "tiff to
383
408
  # jpg" or something like that. Once you run it, the instance is pointing to
@@ -436,6 +461,9 @@ module MiniMagick
436
461
  @info.clear
437
462
 
438
463
  self
464
+ rescue MiniMagick::Invalid, MiniMagick::Error => e
465
+ new_tempfile.unlink if new_tempfile && @tempfile != new_tempfile
466
+ raise e
439
467
  end
440
468
 
441
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}"
@@ -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 = 10
12
- TINY = 1
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.10.1
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-01-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
@@ -118,7 +118,6 @@ files:
118
118
  - lib/mini_magick/configuration.rb
119
119
  - lib/mini_magick/image.rb
120
120
  - lib/mini_magick/image/info.rb
121
- - lib/mini_magick/immutable_image.rb
122
121
  - lib/mini_magick/shell.rb
123
122
  - lib/mini_magick/tool.rb
124
123
  - lib/mini_magick/tool/animate.rb
@@ -140,7 +139,7 @@ homepage: https://github.com/minimagick/minimagick
140
139
  licenses:
141
140
  - MIT
142
141
  metadata: {}
143
- post_install_message:
142
+ post_install_message:
144
143
  rdoc_options: []
145
144
  require_paths:
146
145
  - lib
@@ -156,8 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
155
  version: '0'
157
156
  requirements:
158
157
  - You must have ImageMagick or GraphicsMagick installed
159
- rubygems_version: 3.1.2
160
- signing_key:
158
+ rubygems_version: 3.3.3
159
+ signing_key:
161
160
  specification_version: 4
162
161
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
163
162
  test_files: []
@@ -1,18 +0,0 @@
1
- module MiniMagick
2
- class Image
3
- def initialize(source)
4
- if source.is_a?(String) || source.is_a?(Pathname)
5
- @source_path = source.to_s
6
- elsif source.respond_to?(:path)
7
- @source_path = source.path
8
- else
9
- fail ArgumentError, "invalid source object: #{source.inspect} (expected String, Pathname or #path)"
10
- end
11
- end
12
-
13
- def method_missing
14
- end
15
- end
16
- end
17
-
18
- image = MiniMagick::Image.new()