vips-process 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9deb204f6b71b3f7852df3ffc080c35950492d36
4
- data.tar.gz: cedc593219e56669c6f08af4e025018ebcee9a2b
3
+ metadata.gz: c51f2c88fa8a378ac164a1863695938b45c2df54
4
+ data.tar.gz: 435837441b999517d739e1060736ec7dee8f4313
5
5
  SHA512:
6
- metadata.gz: 237f1a3f7d85a03757b45a40fe182f53b7a798ad068dc35f95188d735a68dfeeddf170a98f87f76773f2ec7abae30d75389161633cc6d5b709f3448435f3ead0
7
- data.tar.gz: 5a285a3c0650df4f1a11fdd25185aeebd27766b8198cc9955ac3f58d94268359d6d76272d3da8d58b1057ebdb21f6e0e07311db4ea2190fb087e00ce23c8df55
6
+ metadata.gz: 1e292db767e36cdd163ff239b206e25ddb505f5186b936245f32dd2c466bd9a0327a26bdf396c79f9d427d73a096e617861c37ab37fae8f11ba7c052ddd05135
7
+ data.tar.gz: dc3c86e46cbba16ac3fd46dd4140a3e75551bd96e161f5503d5a2ff4d040b9a50d9fe5b7b0793a5d8c5f547e0dbc4142d0526c6da3225584a4e687367663ac64
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vips-process (0.2.1)
4
+ vips-process (0.2.2)
5
5
  ruby-vips (~> 0.3.9)
6
6
 
7
7
  GEM
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)
@@ -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 ||= image.x_size
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
@@ -1,5 +1,5 @@
1
1
  module Vips
2
2
  module Process
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
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.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-05 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-vips