image_processing 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of image_processing might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +10 -0
- data/lib/image_processing/chainable.rb +16 -11
- data/lib/image_processing/mini_magick.rb +25 -14
- data/lib/image_processing/processor.rb +0 -10
- data/lib/image_processing/version.rb +1 -1
- data/lib/image_processing/vips.rb +7 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39c52030a178edeef33439eb70807d86935b1e05bbf250d0f30aa9a4947f6dea
|
4
|
+
data.tar.gz: 60c936577febb87380de300024a8f4517ae9dafed394d74fe7b0f78ab04efd7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bc68c91084d44b3052a47ac332d21840965537163b541ef09cd662d729c26e152b3e588f97fd954a13aaae0a5a645be86389a79308de4eee154feb7fed95baa
|
7
|
+
data.tar.gz: 4c026c8eb9cc4dfa537ef3f0f86b460a8dc0a13134fe441604483b6a4b1afd1048911b499673807fac82f7a15c37773e27fad1dd2d049f8e8adedd5204166923
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 1.2.0 (2018-04-18)
|
2
|
+
|
3
|
+
* [minimagick] Allow appending "+" operators in `#loader` and `#saver` using the value `false` (@janko-m)
|
4
|
+
|
5
|
+
* [core] Fix `#apply` not accepting a Hash as an argument (@janko-m)
|
6
|
+
|
7
|
+
* [core] Allow sending any builder commands via `#apply`, not just operations (@janko-m)
|
8
|
+
|
9
|
+
* [minimagick] Add `#define` as a wrapper around `-define` (@janko-m)
|
10
|
+
|
1
11
|
## 1.1.0 (2018-04-05)
|
2
12
|
|
3
13
|
* [minimagick] Disallow splitting multi-layer images into multiple single-layer
|
@@ -16,24 +16,29 @@ module ImageProcessing
|
|
16
16
|
branch saver: options
|
17
17
|
end
|
18
18
|
|
19
|
-
def apply(operations)
|
20
|
-
operation :apply, operations
|
21
|
-
end
|
22
|
-
|
23
19
|
def custom(&block)
|
24
20
|
operation :custom, block
|
25
21
|
end
|
26
22
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
def apply(operations)
|
24
|
+
operations.inject(self) do |builder, (name, argument)|
|
25
|
+
if argument == true || argument == nil
|
26
|
+
builder.send(name)
|
27
|
+
elsif argument.is_a?(Array)
|
28
|
+
builder.send(name, *argument)
|
29
|
+
else
|
30
|
+
builder.send(name, argument)
|
31
|
+
end
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
35
|
+
def method_missing(name, *args)
|
36
|
+
return super if name.to_s.end_with?("?")
|
37
|
+
return send(name.to_s.chomp("!"), *args).call if name.to_s.end_with?("!")
|
38
|
+
|
39
|
+
operation name, *args
|
40
|
+
end
|
41
|
+
|
37
42
|
def operation(name, *args)
|
38
43
|
branch operations: [[name, args]]
|
39
44
|
end
|
@@ -3,6 +3,8 @@ require "image_processing"
|
|
3
3
|
|
4
4
|
module ImageProcessing
|
5
5
|
module MiniMagick
|
6
|
+
extend Chainable
|
7
|
+
|
6
8
|
def self.valid_image?(file)
|
7
9
|
::MiniMagick::Tool::Convert.new do |convert|
|
8
10
|
convert << file.path
|
@@ -41,6 +43,22 @@ module ImageProcessing
|
|
41
43
|
magick.extent "#{width}x#{height}"
|
42
44
|
end
|
43
45
|
|
46
|
+
def define(magick, options)
|
47
|
+
return magick.define(options) if options.is_a?(String)
|
48
|
+
|
49
|
+
options.each do |namespace, options|
|
50
|
+
namespace = namespace.to_s.gsub("_", "-")
|
51
|
+
|
52
|
+
options.each do |key, value|
|
53
|
+
key = key.to_s.gsub("_", "-")
|
54
|
+
|
55
|
+
magick.define "#{namespace}:#{key}=#{value}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
magick
|
60
|
+
end
|
61
|
+
|
44
62
|
def limits(magick, options)
|
45
63
|
limit_args = options.flat_map { |type, value| %W[-limit #{type} #{value}] }
|
46
64
|
prepend_args(magick, limit_args)
|
@@ -95,20 +113,15 @@ module ImageProcessing
|
|
95
113
|
end
|
96
114
|
|
97
115
|
def apply_options(magick, define: {}, **options)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
define.each do |namespace, options|
|
104
|
-
namespace = namespace.to_s.gsub("_", "-")
|
105
|
-
|
106
|
-
options.each do |key, value|
|
107
|
-
key = key.to_s.gsub("_", "-")
|
108
|
-
|
109
|
-
magick.define "#{namespace}:#{key}=#{value}"
|
116
|
+
options.each do |option, value|
|
117
|
+
case value
|
118
|
+
when true, nil then magick.send(option)
|
119
|
+
when false then magick.send(option).+
|
120
|
+
else magick.send(option, *value)
|
110
121
|
end
|
111
122
|
end
|
123
|
+
|
124
|
+
define(magick, define)
|
112
125
|
end
|
113
126
|
|
114
127
|
def prepend_args(magick, args)
|
@@ -125,7 +138,5 @@ module ImageProcessing
|
|
125
138
|
end
|
126
139
|
end
|
127
140
|
end
|
128
|
-
|
129
|
-
extend Chainable
|
130
141
|
end
|
131
142
|
end
|
@@ -4,16 +4,6 @@ module ImageProcessing
|
|
4
4
|
@pipeline = pipeline
|
5
5
|
end
|
6
6
|
|
7
|
-
def apply(image, operations)
|
8
|
-
operations.inject(image) do |result, (name, args)|
|
9
|
-
if args == true || args.nil?
|
10
|
-
apply_operation(name, result)
|
11
|
-
else
|
12
|
-
apply_operation(name, result, *args)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
7
|
def apply_operation(name, image, *args)
|
18
8
|
if respond_to?(name)
|
19
9
|
public_send(name, image, *args)
|
@@ -5,6 +5,8 @@ fail "image_processing/vips requires libvips 8.6+" unless Vips.at_least_libvips?
|
|
5
5
|
|
6
6
|
module ImageProcessing
|
7
7
|
module Vips
|
8
|
+
extend Chainable
|
9
|
+
|
8
10
|
def self.valid_image?(file)
|
9
11
|
::Vips::Image.new_from_file(file.path, access: :sequential).avg
|
10
12
|
true
|
@@ -26,23 +28,23 @@ module ImageProcessing
|
|
26
28
|
|
27
29
|
def resize_to_limit(image, width, height, **options)
|
28
30
|
width, height = default_dimensions(width, height)
|
29
|
-
|
31
|
+
thumbnail(image, width, height, size: :down, **options)
|
30
32
|
end
|
31
33
|
|
32
34
|
def resize_to_fit(image, width, height, **options)
|
33
35
|
width, height = default_dimensions(width, height)
|
34
|
-
|
36
|
+
thumbnail(image, width, height, **options)
|
35
37
|
end
|
36
38
|
|
37
39
|
def resize_to_fill(image, width, height, **options)
|
38
|
-
|
40
|
+
thumbnail(image, width, height, crop: :centre, **options)
|
39
41
|
end
|
40
42
|
|
41
43
|
def resize_and_pad(image, width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options)
|
42
44
|
embed_options = { extend: extend, background: background }
|
43
45
|
embed_options.reject! { |name, value| value.nil? }
|
44
46
|
|
45
|
-
image =
|
47
|
+
image = thumbnail(image, width, height, **options)
|
46
48
|
image = add_alpha(image) if alpha && !has_alpha?(image)
|
47
49
|
image.gravity(gravity, width, height, **embed_options)
|
48
50
|
end
|
@@ -70,7 +72,7 @@ module ImageProcessing
|
|
70
72
|
|
71
73
|
private
|
72
74
|
|
73
|
-
def
|
75
|
+
def thumbnail(image, width, height, sharpen: SHARPEN_MASK, **options)
|
74
76
|
image = image.thumbnail_image(width, height: height, **options)
|
75
77
|
image = image.conv(sharpen) if sharpen
|
76
78
|
image
|
@@ -116,7 +118,5 @@ module ImageProcessing
|
|
116
118
|
options.select { |name, value| operation_options.include?(name) }
|
117
119
|
end
|
118
120
|
end
|
119
|
-
|
120
|
-
extend Chainable
|
121
121
|
end
|
122
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_magick
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
155
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.6
|
156
|
+
rubygems_version: 2.7.6
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: Set of higher-level helper methods for image processing.
|