Class: ImageScience
- Inherits:
-
Object
- Object
- ImageScience
- Defined in:
- lib/image_science.rb
Overview
Provides a clean and simple API to generate thumbnails using FreeImage as the underlying mechanism.
For more information or if you have build issues with FreeImage, see seattlerb.rubyforge.org/ImageScience.html
Constant Summary collapse
- VERSION =
'1.3.2'
Instance Method Summary collapse
-
#cropped_thumbnail(size) ⇒ Object
Creates a square thumbnail of the image cropping the longest edge to match the shortest edge, resizes to
size, and yields the new image. -
#thumbnail(size) ⇒ Object
Creates a proportional thumbnail of the image scaled so its longest edge is resized to
sizeand yields the new image.
Instance Method Details
#cropped_thumbnail(size) ⇒ Object
Creates a square thumbnail of the image cropping the longest edge to match the shortest edge, resizes to size, and yields the new image.
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/image_science.rb', line 78 def cropped_thumbnail(size) # :yields: image w, h = width, height l, t, r, b, half = 0, 0, w, h, (w - h).abs / 2 l, r = half, half + h if w > h t, b = half, half + w if h > w with_crop(l, t, r, b) do |img| img.thumbnail(size) do |thumb| yield thumb end end end |
#thumbnail(size) ⇒ Object
Creates a proportional thumbnail of the image scaled so its longest edge is resized to size and yields the new image.
64 65 66 67 68 69 70 71 |
# File 'lib/image_science.rb', line 64 def thumbnail(size) # :yields: image w, h = width, height scale = size.to_f / (w > h ? w : h) self.resize((w * scale).round, (h * scale).round) do |image| yield image end end |