image_processing 0.10.3 → 0.11.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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +2 -20
- data/lib/image_processing/mini_magick/deprecated_api.rb +2 -1
- data/lib/image_processing/mini_magick.rb +46 -10
- data/lib/image_processing/version.rb +1 -1
- data/lib/image_processing/vips.rb +12 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e049246f3103f7f178b7318bf8dcf13695e4176d
|
4
|
+
data.tar.gz: 62cfaf744d25bdee1db2c6a070ffabe52c3df89f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15e19280b7889ac52b21c435be6d132a535cd94c31e38eb5a85fe47b9ad210963117fded9b53a444dc2c0cbc08962808cd38cb25f5c70902bc0509d5a70ad23f
|
7
|
+
data.tar.gz: 236da6230651462334d51dabaf975e59e070001ae8269dfb6ff206de88ce86496fafa65b1fa4f89ea3bed8d866e06276eb192f57fe4829d150e3a4cb35bbf0ea
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 0.11.0 (2018-03-27)
|
2
|
+
|
3
|
+
* [minimagick] Fix broken deprecated `#convert` (@janko-m)
|
4
|
+
|
5
|
+
* [minimagick] Add `#limit` for specifying resource limits using `-limit` (@janko-m)
|
6
|
+
|
7
|
+
* [minimagick] Use `-thumbnail` instead of `-resize` in `#resize_*` methods (@janko-m)
|
8
|
+
|
9
|
+
* [minimagick] Add loader and saver options (@janko-m)
|
10
|
+
|
1
11
|
## 0.10.3 (2018-03-24)
|
2
12
|
|
3
13
|
* [minimagick] Fix bang methods in deprecated API calling nondestructive versions (@janko-m)
|
data/README.md
CHANGED
@@ -99,25 +99,7 @@ You can continue reading the API documentation for specific modules:
|
|
99
99
|
* **[`ImageProcessing::Vips`]**
|
100
100
|
* **[`ImageProcessing::MiniMagick`]**
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
After images have been processed, you might want to additionally optimize them
|
105
|
-
to reduce their filesize. You can do that with the [image_optim] gem:
|
106
|
-
|
107
|
-
```rb
|
108
|
-
require "image_optim"
|
109
|
-
|
110
|
-
result = ImageProcessing::Vips
|
111
|
-
.resize_to_limit(400, 400)
|
112
|
-
.saver(Q: 85)
|
113
|
-
.call(image)
|
114
|
-
|
115
|
-
image_optim = ImageOptim.new(...)
|
116
|
-
image_optim.optimize_image!(result.path)
|
117
|
-
result.open # refresh file descriptor
|
118
|
-
|
119
|
-
result # optimized image
|
120
|
-
```
|
102
|
+
See the **[wiki]** for additional "How To" guides for common scenarios.
|
121
103
|
|
122
104
|
## Contributing
|
123
105
|
|
@@ -148,5 +130,5 @@ The `ImageProcessing::MiniMagick` functionality was extracted from
|
|
148
130
|
[VIPS]: http://jcupitt.github.io/libvips/
|
149
131
|
[`ImageProcessing::Vips`]: /doc/vips.md#imageprocessingvips
|
150
132
|
[`ImageProcessing::MiniMagick`]: /doc/minimagick.md#imageprocessingminimagick
|
151
|
-
[image_optim]: https://github.com/toy/image_optim
|
152
133
|
[refile-mini_magick]: https://github.com/refile/refile-mini_magick
|
134
|
+
[wiki]: https://github.com/janko-m/image_processing/wiki
|
@@ -19,7 +19,6 @@ module ImageProcessing
|
|
19
19
|
|
20
20
|
class Processor
|
21
21
|
IMAGE_CLASS = ::MiniMagick::Tool
|
22
|
-
TRANSPARENT = "rgba(255,255,255,0.0)"
|
23
22
|
|
24
23
|
def apply_operation(name, magick, *args)
|
25
24
|
if respond_to?(name)
|
@@ -30,40 +29,49 @@ module ImageProcessing
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def resize_to_limit(magick, width, height)
|
33
|
-
magick.
|
32
|
+
magick.thumbnail "#{width}x#{height}>"
|
34
33
|
end
|
35
34
|
|
36
35
|
def resize_to_fit(magick, width, height)
|
37
|
-
magick.
|
36
|
+
magick.thumbnail "#{width}x#{height}"
|
38
37
|
end
|
39
38
|
|
40
39
|
def resize_to_fill(magick, width, height, gravity: "Center")
|
41
|
-
magick.
|
40
|
+
magick.thumbnail "#{width}x#{height}^"
|
42
41
|
magick.gravity gravity
|
43
|
-
magick.background
|
42
|
+
magick.background "rgba(255,255,255,0.0)" # transparent
|
44
43
|
magick.extent "#{width}x#{height}"
|
45
44
|
end
|
46
45
|
|
47
|
-
def resize_and_pad(magick, width, height, background:
|
48
|
-
background =
|
46
|
+
def resize_and_pad(magick, width, height, background: :transparent, gravity: "Center")
|
47
|
+
background = "rgba(255,255,255,0.0)" if background.to_s == "transparent"
|
49
48
|
|
50
|
-
magick.
|
49
|
+
magick.thumbnail "#{width}x#{height}"
|
51
50
|
magick.background background
|
52
51
|
magick.gravity gravity
|
53
52
|
magick.extent "#{width}x#{height}"
|
54
53
|
end
|
55
54
|
|
55
|
+
def limit(magick, limits)
|
56
|
+
limit_args = limits.flat_map { |type, value| %W[-limit #{type} #{value}] }
|
57
|
+
magick.args.replace limit_args + magick.args
|
58
|
+
magick
|
59
|
+
end
|
60
|
+
|
56
61
|
def append(magick, *args)
|
57
62
|
magick.merge! args
|
58
63
|
end
|
59
64
|
|
60
|
-
def load_image(path_or_magick, page: nil, geometry: nil, fail: true, auto_orient: true)
|
65
|
+
def load_image(path_or_magick, page: nil, geometry: nil, fail: true, auto_orient: true, define: {}, **options)
|
61
66
|
if path_or_magick.is_a?(::MiniMagick::Tool)
|
62
67
|
magick = path_or_magick
|
63
68
|
else
|
64
69
|
source_path = path_or_magick
|
65
70
|
magick = ::MiniMagick::Tool::Convert.new
|
66
71
|
|
72
|
+
apply_define(magick, define)
|
73
|
+
apply_options(magick, options)
|
74
|
+
|
67
75
|
input_path = source_path
|
68
76
|
input_path += "[#{page}]" if page
|
69
77
|
input_path += "[#{geometry}]" if geometry
|
@@ -77,10 +85,38 @@ module ImageProcessing
|
|
77
85
|
magick
|
78
86
|
end
|
79
87
|
|
80
|
-
def save_image(magick, destination_path, **options)
|
88
|
+
def save_image(magick, destination_path, define: {}, **options)
|
89
|
+
apply_define(magick, define)
|
90
|
+
apply_options(magick, options)
|
91
|
+
|
81
92
|
magick << destination_path
|
93
|
+
|
82
94
|
magick.call
|
83
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def apply_define(magick, define)
|
100
|
+
define.each do |namespace, options|
|
101
|
+
namespace = namespace.to_s.gsub("_", "-")
|
102
|
+
|
103
|
+
options.each do |key, value|
|
104
|
+
key = key.to_s.gsub("_", "-")
|
105
|
+
|
106
|
+
magick.define "#{namespace}:#{key}=#{value}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def apply_options(magick, options)
|
112
|
+
options.each do |option, value|
|
113
|
+
case value
|
114
|
+
when true then magick.send(option)
|
115
|
+
when false then magick.send(option).+
|
116
|
+
else magick.send(option, *value)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
84
120
|
end
|
85
121
|
|
86
122
|
extend Chainable
|
@@ -57,8 +57,7 @@ module ImageProcessing
|
|
57
57
|
image = path_or_image
|
58
58
|
else
|
59
59
|
source_path = path_or_image
|
60
|
-
|
61
|
-
options = select_valid_options(loader, options) if loader
|
60
|
+
options = select_valid_loader_options(source_path, options)
|
62
61
|
|
63
62
|
image = ::Vips::Image.new_from_file(source_path, fail: true, **options)
|
64
63
|
end
|
@@ -68,8 +67,7 @@ module ImageProcessing
|
|
68
67
|
end
|
69
68
|
|
70
69
|
def save_image(image, destination_path, **options)
|
71
|
-
|
72
|
-
options = select_valid_options(saver, options) if saver
|
70
|
+
options = select_valid_saver_options(destination_path, options)
|
73
71
|
|
74
72
|
image.write_to_file(destination_path, **options)
|
75
73
|
end
|
@@ -82,6 +80,16 @@ module ImageProcessing
|
|
82
80
|
[width || MAX_COORD, height || MAX_COORD]
|
83
81
|
end
|
84
82
|
|
83
|
+
def select_valid_loader_options(source_path, options)
|
84
|
+
loader = ::Vips.vips_foreign_find_load(source_path)
|
85
|
+
loader ? select_valid_options(loader, options) : options
|
86
|
+
end
|
87
|
+
|
88
|
+
def select_valid_saver_options(destination_path, options)
|
89
|
+
saver = ::Vips.vips_foreign_find_save(destination_path)
|
90
|
+
saver ? select_valid_options(saver, options) : options
|
91
|
+
end
|
92
|
+
|
85
93
|
def select_valid_options(operation_name, options)
|
86
94
|
operation = ::Vips::Operation.new(operation_name)
|
87
95
|
|
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: 0.
|
4
|
+
version: 0.11.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-03-
|
11
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|