mini_magick 3.8.0 → 4.0.0.rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mini_gmagick.rb +2 -1
- data/lib/mini_magick/configuration.rb +136 -0
- data/lib/mini_magick/image/info.rb +104 -0
- data/lib/mini_magick/image.rb +384 -345
- data/lib/mini_magick/logger.rb +40 -0
- data/lib/mini_magick/shell.rb +46 -0
- data/lib/mini_magick/tool/animate.rb +14 -0
- data/lib/mini_magick/tool/compare.rb +14 -0
- data/lib/mini_magick/tool/composite.rb +14 -0
- data/lib/mini_magick/tool/conjure.rb +14 -0
- data/lib/mini_magick/tool/convert.rb +14 -0
- data/lib/mini_magick/tool/display.rb +14 -0
- data/lib/mini_magick/tool/identify.rb +14 -0
- data/lib/mini_magick/tool/import.rb +14 -0
- data/lib/mini_magick/tool/mogrify.rb +14 -0
- data/lib/mini_magick/tool/montage.rb +14 -0
- data/lib/mini_magick/tool/stream.rb +14 -0
- data/lib/mini_magick/tool.rb +233 -0
- data/lib/mini_magick/utilities.rb +25 -26
- data/lib/mini_magick/version.rb +15 -1
- data/lib/mini_magick.rb +43 -79
- data/spec/fixtures/animation.gif +0 -0
- data/spec/fixtures/default.jpg +0 -0
- data/spec/fixtures/exif.jpg +0 -0
- data/spec/fixtures/image.psd +0 -0
- data/spec/fixtures/not_an_image.rb +1 -0
- data/spec/lib/mini_magick/configuration_spec.rb +66 -0
- data/spec/lib/mini_magick/image_spec.rb +407 -0
- data/spec/lib/mini_magick/shell_spec.rb +66 -0
- data/spec/lib/mini_magick/tool_spec.rb +90 -0
- data/spec/lib/mini_magick/utilities_spec.rb +17 -0
- data/spec/lib/mini_magick_spec.rb +39 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/helpers.rb +37 -0
- metadata +52 -54
- data/lib/mini_magick/command_builder.rb +0 -110
- data/lib/mini_magick/errors.rb +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2e11b9e22bbabb55096ee32c8635e5302459b234
|
|
4
|
+
data.tar.gz: ed3df8df5bd3c55605760ce4d68eb070180fd890
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e97b6cce0e021ab9f21a31e74e9b8afe9aca5e95c722fcd1230d31a3ece8310bed90fe91f2dc131a783a3e9c987217cc962b6fc296926c6f73fbb8ab263ce06d
|
|
7
|
+
data.tar.gz: 7f489774f7ce93a2e63d5fce3d12ddea5f70aa2a98b6343ff5f49df3cf66f67d9f8fbcd135f9eb9d3214e5160af7bfcc82d425895e5491dbe5194228b66a2b50
|
data/lib/mini_gmagick.rb
CHANGED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'mini_magick/utilities'
|
|
2
|
+
|
|
3
|
+
module MiniMagick
|
|
4
|
+
module Configuration
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
# Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
|
|
8
|
+
# [GraphicsMagick](http://www.graphicsmagick.org).
|
|
9
|
+
#
|
|
10
|
+
# @return [Symbol] `:imagemagick` or `:minimagick`
|
|
11
|
+
#
|
|
12
|
+
attr_accessor :cli
|
|
13
|
+
# @private (for backwards compatibility)
|
|
14
|
+
attr_accessor :processor
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# If you don't have the CLI tools in your PATH, you can set the path to the
|
|
18
|
+
# executables.
|
|
19
|
+
#
|
|
20
|
+
# @return [String]
|
|
21
|
+
#
|
|
22
|
+
attr_accessor :cli_path
|
|
23
|
+
# @private (for backwards compatibility)
|
|
24
|
+
attr_accessor :processor_path
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# If you don't want commands to take too long, you can set a timeout (in
|
|
28
|
+
# seconds).
|
|
29
|
+
#
|
|
30
|
+
# @return [Integer]
|
|
31
|
+
#
|
|
32
|
+
attr_accessor :timeout
|
|
33
|
+
##
|
|
34
|
+
# When set to `true`, it outputs each command to STDOUT in their shell
|
|
35
|
+
# version.
|
|
36
|
+
#
|
|
37
|
+
# @return [Boolean]
|
|
38
|
+
#
|
|
39
|
+
attr_accessor :debug
|
|
40
|
+
##
|
|
41
|
+
# Logger for {#debug}, default is `MiniMagick::Logger.new(STDOUT)`, but
|
|
42
|
+
# you can override it, for example if you want the logs to be written to
|
|
43
|
+
# a file.
|
|
44
|
+
#
|
|
45
|
+
# @return [Logger]
|
|
46
|
+
#
|
|
47
|
+
attr_accessor :logger
|
|
48
|
+
##
|
|
49
|
+
# If set to `true`, it will `identify` every newly created image, and raise
|
|
50
|
+
# `MiniMagick::Invalid` if the image is not valid. Useful for validating
|
|
51
|
+
# user input, although it adds a bit of overhead. Defaults to `true`.
|
|
52
|
+
#
|
|
53
|
+
# @return [Boolean]
|
|
54
|
+
#
|
|
55
|
+
attr_accessor :validate_on_create
|
|
56
|
+
##
|
|
57
|
+
# If set to `true`, it will `identify` every image that gets written (with
|
|
58
|
+
# {MiniMagick::Image#write}), and raise `MiniMagick::Invalid` if the image
|
|
59
|
+
# is not valid. Useful for validating that processing was sucessful,
|
|
60
|
+
# although it adds a bit of overhead. Defaults to `true`.
|
|
61
|
+
#
|
|
62
|
+
# @return [Boolean]
|
|
63
|
+
#
|
|
64
|
+
attr_accessor :validate_on_write
|
|
65
|
+
|
|
66
|
+
def self.extended(base)
|
|
67
|
+
base.validate_on_create = true
|
|
68
|
+
base.validate_on_write = true
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
##
|
|
72
|
+
# @yield [self]
|
|
73
|
+
# @example
|
|
74
|
+
# MiniMagick.configure do |config|
|
|
75
|
+
# config.cli = :graphicsmagick
|
|
76
|
+
# config.timeout = 5
|
|
77
|
+
# end
|
|
78
|
+
#
|
|
79
|
+
def configure
|
|
80
|
+
yield self
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def processor
|
|
84
|
+
@processor ||= ["mogrify", "gm"].detect do |processor|
|
|
85
|
+
MiniMagick::Utilities.which(processor)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def processor=(processor)
|
|
90
|
+
@processor = processor.to_s
|
|
91
|
+
|
|
92
|
+
unless ["mogrify", "gm"].include?(@processor)
|
|
93
|
+
raise ArgumentError,
|
|
94
|
+
"processor has to be set to either \"mogrify\" or \"gm\"" \
|
|
95
|
+
", was set to #{@processor.inspect}"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
reload_tools
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def cli
|
|
102
|
+
@cli ||
|
|
103
|
+
case processor.to_s
|
|
104
|
+
when "mogrify" then :imagemagick
|
|
105
|
+
when "gm" then :graphicsmagick
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def cli=(value)
|
|
110
|
+
@cli = value
|
|
111
|
+
|
|
112
|
+
unless [:imagemagick, :graphicsmagick].include?(@cli)
|
|
113
|
+
raise ArgumentError,
|
|
114
|
+
"CLI has to be set to either :imagemagick or :graphicsmagick" \
|
|
115
|
+
", was set to #{@cli.inspect}"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
reload_tools
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def cli_path
|
|
122
|
+
@cli_path || @processor_path
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def logger
|
|
126
|
+
@logger || MiniMagick::Logger.new($stdout)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private
|
|
130
|
+
|
|
131
|
+
def reload_tools
|
|
132
|
+
MiniMagick::Tool::OptionMethods.instances.each(&:reload_methods)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
module MiniMagick
|
|
2
|
+
class Image
|
|
3
|
+
# @private
|
|
4
|
+
class Info
|
|
5
|
+
|
|
6
|
+
def initialize(path)
|
|
7
|
+
@path = path
|
|
8
|
+
@info = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def [](value, *args)
|
|
12
|
+
case value
|
|
13
|
+
when "format", "width", "height", "dimensions", "size"
|
|
14
|
+
cheap_info(value)
|
|
15
|
+
when "colorspace"
|
|
16
|
+
colorspace
|
|
17
|
+
when "mime_type"
|
|
18
|
+
mime_type
|
|
19
|
+
when "resolution"
|
|
20
|
+
resolution(*args)
|
|
21
|
+
when /^EXIF\:/i
|
|
22
|
+
raw_exif(value)
|
|
23
|
+
when "exif"
|
|
24
|
+
exif
|
|
25
|
+
else
|
|
26
|
+
raw(value)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def clear
|
|
31
|
+
@info.clear
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def cheap_info(value)
|
|
37
|
+
@info.fetch(value) do
|
|
38
|
+
format, width, height, size = self["%m %w %h %b"].split(" ")
|
|
39
|
+
|
|
40
|
+
@info.update(
|
|
41
|
+
"format" => format,
|
|
42
|
+
"width" => Integer(width),
|
|
43
|
+
"height" => Integer(height),
|
|
44
|
+
"dimensions" => [Integer(width), Integer(height)],
|
|
45
|
+
"size" => size.to_i,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
@info.fetch(value)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def colorspace
|
|
53
|
+
@info.fetch("colorspace") do
|
|
54
|
+
@info["colorspace"] = self["%r"]
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def mime_type
|
|
59
|
+
"image/#{self["format"].downcase}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def resolution(unit = nil)
|
|
63
|
+
output = identify do |b|
|
|
64
|
+
b.units unit if unit
|
|
65
|
+
b.format "%x %y"
|
|
66
|
+
end
|
|
67
|
+
output.split(" ").map(&:to_i)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def raw_exif(value)
|
|
71
|
+
self["%[#{value}]"]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def exif
|
|
75
|
+
@info.fetch("exif") do
|
|
76
|
+
output = self["%[EXIF:*]"]
|
|
77
|
+
pairs = output.gsub(/^exif:/, "").split("\n").map { |line| line.split("=") }
|
|
78
|
+
exif = Hash[pairs].tap do |hash|
|
|
79
|
+
hash.each do |key, value|
|
|
80
|
+
if value.include?(",")
|
|
81
|
+
# Sometimes exif comes in a comma-separated list of character values
|
|
82
|
+
hash[key] = value.scan(/\d+/).map(&:to_i).map(&:chr).join
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
@info["exif"] = exif
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def raw(value)
|
|
92
|
+
identify { |b| b.format(value) }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def identify
|
|
96
|
+
MiniMagick::Tool::Identify.new do |builder|
|
|
97
|
+
yield builder if block_given?
|
|
98
|
+
builder << "#{@path}[0]"
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|