image_processing 0.2.1 → 0.2.2
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/README.md +6 -2
- data/lib/image_processing/mini_magick.rb +23 -7
- data/lib/image_processing/version.rb +1 -1
- 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: ffdeedc6dde0dbff761a5185ebbc0316ab9d70bd
|
4
|
+
data.tar.gz: 42409b4d185f80c1462ee7aebe46e89daf2141ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5da67c6c7794556ae3976acb86aaffe91f4fda1ae0363c2a179ce68d1a89b58bcc9c3b952d65d3dd9ca62c800a710b3e993b1e65da4ada0283541b250971f232
|
7
|
+
data.tar.gz: 1c870e3254d44fea11e201a602df454bcb0201f9f0c668d18b551a838f9b720ee19da90ba043bd2a55f641bcb1664e0b197c2556ed0dba90080695a22503e9ca
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# ImageProcessing
|
2
2
|
|
3
3
|
Provides higher-level helper methods for image processing in Ruby using
|
4
|
-
ImageMagick.
|
5
|
-
|
4
|
+
ImageMagick.
|
5
|
+
|
6
|
+
This methods were extracted from Refile, and were made generic so that they can
|
7
|
+
be used in any project. The goal is to have a centralized place where image
|
8
|
+
processing helper methods are maintained, instead of CarrierWave, Dragonfly and
|
9
|
+
Refile each having their own.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
@@ -24,12 +24,28 @@ module ImageProcessing
|
|
24
24
|
# @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
|
25
25
|
# @return [File, Tempfile]
|
26
26
|
def convert!(image, format, &block)
|
27
|
-
|
27
|
+
with_minimagick(image) do |img|
|
28
28
|
img.format(format.downcase, nil, &block)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
nondestructive_alias :convert, :convert!
|
32
32
|
|
33
|
+
# Adjusts the image so that its orientation is suitable for viewing.
|
34
|
+
#
|
35
|
+
# @see http://www.imagemagick.org/script/command-line-options.php#auto-orient
|
36
|
+
# @param [MiniMagick::Image] image the image to convert
|
37
|
+
# @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
|
38
|
+
# @return [File, Tempfile]
|
39
|
+
def auto_orient!(image)
|
40
|
+
with_minimagick(image) do |img|
|
41
|
+
img.combine_options do |cmd|
|
42
|
+
yield cmd if block_given?
|
43
|
+
cmd.auto_orient
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
nondestructive_alias :auto_orient, :auto_orient!
|
48
|
+
|
33
49
|
# Resize the image to fit within the specified dimensions while retaining
|
34
50
|
# the original aspect ratio. Will only resize the image if it is larger
|
35
51
|
# than the specified dimensions. The resulting image may be shorter or
|
@@ -42,7 +58,7 @@ module ImageProcessing
|
|
42
58
|
# @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
|
43
59
|
# @return [File, Tempfile]
|
44
60
|
def resize_to_limit!(image, width, height)
|
45
|
-
|
61
|
+
with_minimagick(image) do |img|
|
46
62
|
img.combine_options do |cmd|
|
47
63
|
yield cmd if block_given?
|
48
64
|
cmd.resize "#{width}x#{height}>"
|
@@ -62,7 +78,7 @@ module ImageProcessing
|
|
62
78
|
# @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
|
63
79
|
# @return [File, Tempfile]
|
64
80
|
def resize_to_fit!(image, width, height)
|
65
|
-
|
81
|
+
with_minimagick(image) do |img|
|
66
82
|
img.combine_options do |cmd|
|
67
83
|
yield cmd if block_given?
|
68
84
|
cmd.resize "#{width}x#{height}"
|
@@ -88,7 +104,7 @@ module ImageProcessing
|
|
88
104
|
# @return [File, Tempfile]
|
89
105
|
# @see http://www.imagemagick.org/script/command-line-options.php#gravity
|
90
106
|
def resize_to_fill!(image, width, height, gravity: "Center")
|
91
|
-
|
107
|
+
with_minimagick(image) do |img|
|
92
108
|
img.combine_options do |cmd|
|
93
109
|
yield cmd if block_given?
|
94
110
|
cmd.resize "#{width}x#{height}^"
|
@@ -121,7 +137,7 @@ module ImageProcessing
|
|
121
137
|
# @see http://www.imagemagick.org/script/color.php
|
122
138
|
# @see http://www.imagemagick.org/script/command-line-options.php#gravity
|
123
139
|
def resize_and_pad!(image, width, height, background: "transparent", gravity: "Center")
|
124
|
-
|
140
|
+
with_minimagick(image) do |img|
|
125
141
|
img.combine_options do |cmd|
|
126
142
|
yield cmd if block_given?
|
127
143
|
cmd.resize "#{width}x#{height}"
|
@@ -150,7 +166,7 @@ module ImageProcessing
|
|
150
166
|
# @return [File, Tempfile]
|
151
167
|
# @see http://www.imagemagick.org/script/command-line-options.php#resample
|
152
168
|
def resample!(image, width, height)
|
153
|
-
|
169
|
+
with_minimagick(image) do |img|
|
154
170
|
img.combine_options do |cmd|
|
155
171
|
yield cmd if block_given?
|
156
172
|
cmd.resample "#{width}x#{height}"
|
@@ -161,7 +177,7 @@ module ImageProcessing
|
|
161
177
|
|
162
178
|
# Convert an image into a MiniMagick::Image for the duration of the block,
|
163
179
|
# and at the end return a File object.
|
164
|
-
def
|
180
|
+
def with_minimagick(image)
|
165
181
|
image = ::MiniMagick::Image.new(image.path, image)
|
166
182
|
yield image
|
167
183
|
image.instance_variable_get("@tempfile")
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|