vips-process 0.2.2 → 0.2.3
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/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/vips-process/crop.rb +22 -6
- data/lib/vips-process/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: c51f2c88fa8a378ac164a1863695938b45c2df54
|
|
4
|
+
data.tar.gz: 435837441b999517d739e1060736ec7dee8f4313
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e292db767e36cdd163ff239b206e25ddb505f5186b936245f32dd2c466bd9a0327a26bdf396c79f9d427d73a096e617861c37ab37fae8f11ba7c052ddd05135
|
|
7
|
+
data.tar.gz: dc3c86e46cbba16ac3fd46dd4140a3e75551bd96e161f5503d5a2ff4d040b9a50d9fe5b7b0793a5d8c5f547e0dbc4142d0526c6da3225584a4e687367663ac64
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -236,6 +236,10 @@ E.g.: say you have an image that is 3000x2000 px.
|
|
|
236
236
|
resized image. It will give you an image of full width but with height starting at 25px and
|
|
237
237
|
finishing at 175px. Here's a graphical example:
|
|
238
238
|
|
|
239
|
+
If the cropping area is outside of the boundaries of the current image `crop` will throw an
|
|
240
|
+
Exception. If you would like it to silently ignore that issue and return the image as it came
|
|
241
|
+
use `crop!` instead.
|
|
242
|
+
|
|
239
243
|
### Quality
|
|
240
244
|
|
|
241
245
|
Changes quality of the image (if supported by the file format)
|
data/lib/vips-process/crop.rb
CHANGED
|
@@ -66,15 +66,31 @@ module Vips
|
|
|
66
66
|
#
|
|
67
67
|
def crop(left: 0, top: 0, width: nil, height: nil)
|
|
68
68
|
manipulate! do |image|
|
|
69
|
-
width
|
|
70
|
-
height ||= image.y_size
|
|
71
|
-
top = top.is_a?(Float) && top.between?(0,1) ? (image.y_size - height) * top : top
|
|
72
|
-
left = left.is_a?(Float) && left.between?(0,1) ? (image.x_size - width) * left : left
|
|
73
|
-
|
|
74
|
-
image.extract_area left, top, width, height
|
|
69
|
+
do_crop image, left, top, width, height
|
|
75
70
|
end
|
|
76
71
|
self
|
|
77
72
|
end
|
|
73
|
+
|
|
74
|
+
# Same as #crop but it returns the current image if there was an area issue while cropping
|
|
75
|
+
# instead of raising an exception.
|
|
76
|
+
def crop!(left: 0, top: 0, width: nil, height: nil)
|
|
77
|
+
manipulate! do |image|
|
|
78
|
+
begin
|
|
79
|
+
do_crop image, left, top, width, height
|
|
80
|
+
rescue VIPS::Error => e
|
|
81
|
+
e.message =~ /extract_area/ ? image : raise(e)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private def do_crop(image, left, top, width, height)
|
|
87
|
+
width ||= image.x_size
|
|
88
|
+
height ||= image.y_size
|
|
89
|
+
top = top.is_a?(Float) && top.between?(0,1) ? (image.y_size - height) * top : top
|
|
90
|
+
left = left.is_a?(Float) && left.between?(0,1) ? (image.x_size - width) * left : left
|
|
91
|
+
|
|
92
|
+
image.extract_area left, top, width, height
|
|
93
|
+
end
|
|
78
94
|
end # Crop
|
|
79
95
|
end # Process
|
|
80
96
|
end # Vips
|
data/lib/vips-process/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vips-process
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Darío Javier Cravero
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-10-
|
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby-vips
|