Module: Vips::Process::Resize
- Defined in:
- lib/vips-process/resize.rb
Constant Summary collapse
- SHARPEN_MASK =
begin conv_mask = [ [ -1, -1, -1 ], [ -1, 24, -1 ], [ -1, -1, -1 ] ] ::VIPS::Mask.new conv_mask, 16 end
Instance Method Summary collapse
-
#resize_to_fill(width, height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the aspect ratio of the original image.
-
#resize_to_fit(width, height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the original aspect ratio.
-
#resize_to_height(height) ⇒ Object
Resize the image to a certain height.
-
#resize_to_limit(width, height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the original aspect ratio.
-
#resize_to_width(width) ⇒ Object
Resize the image to a certain width.
Instance Method Details
#resize_to_fill(width, height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the aspect ratio of the original image. If necessary, crop the image in the larger dimension.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vips-process/resize.rb', line 35 def resize_to_fill(width, height) manipulate! do |image| image = resize_image image, width, height, :max top = 0 left = 0 if image.x_size > width left = (image.x_size - width) / 2 elsif image.y_size > height top = (image.y_size - height) / 2 end image.extract_area left, top, width, height end self end |
#resize_to_fit(width, height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
21 22 23 24 25 26 |
# File 'lib/vips-process/resize.rb', line 21 def resize_to_fit(width, height) manipulate! do |image| resize_image image, width, height end self end |
#resize_to_height(height) ⇒ Object
Resize the image to a certain height. It will keep its width in relation.
83 84 85 86 87 88 |
# File 'lib/vips-process/resize.rb', line 83 def resize_to_height(height) manipulate! do |image| resize_image image, image.x_size, height end self end |
#resize_to_limit(width, height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the original aspect ratio. Will only resize the image if it is larger than the specified dimensions. The resulting image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
60 61 62 63 64 65 66 |
# File 'lib/vips-process/resize.rb', line 60 def resize_to_limit(width, height) manipulate! do |image| image = resize_image(image, width, height) if width < image.x_size || height < image.y_size image end self end |
#resize_to_width(width) ⇒ Object
Resize the image to a certain width. It will keep its height in relation.
72 73 74 75 76 77 |
# File 'lib/vips-process/resize.rb', line 72 def resize_to_width(width) manipulate! do |image| resize_image image, width, image.y_size end self end |