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.2.1.tdd'- JPEG_DEFAULT =
These actually come from FreeImage.h.
0- JPEG_FAST =
75%
1- JPEG_ACCURATE =
2- JPEG_QUALITYSUPERB =
100%
0x80- JPEG_QUALITYGOOD =
75%
0x100- JPEG_QUALITYNORMAL =
50%
0x200- JPEG_QUALITYAVERAGE =
25%
0x400- JPEG_QUALITYBAD =
10%
0x800- JPEG_PROGRESSIVE =
save as a progressive-JPEG (use | to combine with other flags)
0x2000
Class Method Summary collapse
-
.with_image(path) ⇒ Object
The top-level image loader opens
pathand then yields the image. -
.with_image_from_memory(data) ⇒ Object
The top-level image loader, opens an image from the string
dataand then yields the image.
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. -
#height ⇒ Object
Returns the height of the image, in pixels.
-
#resize(width, height) ⇒ Object
Resizes the image to
widthandheightusing a cubic-bspline filter and yields the new image. -
#save(path, jpeg_quality = JPEG_QUALITYSUPERB) ⇒ Object
Saves the image out to
path. - #save_with_quality(path, jpeg_quality) ⇒ Object
-
#thumbnail(size) ⇒ Object
Creates a proportional thumbnail of the image scaled so its longest edge is resized to
sizeand yields the new image. -
#width ⇒ Object
Returns the width of the image, in pixels.
-
#with_crop(left, top, right, bottom) ⇒ Object
Crops an image to
left,top,right, andbottomand then yields the new image.
Class Method Details
.with_image(path) ⇒ Object
The top-level image loader opens path and then yields the image.
30 31 |
# File 'lib/image_science.rb', line 30 def self.with_image(path) # :yields: image end |
.with_image_from_memory(data) ⇒ Object
The top-level image loader, opens an image from the string data and then yields the image.
36 37 |
# File 'lib/image_science.rb', line 36 def self.with_image_from_memory(data) # :yields: image end |
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.
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/image_science.rb', line 91 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 |
#height ⇒ Object
Returns the height of the image, in pixels.
54 |
# File 'lib/image_science.rb', line 54 def height; end |
#resize(width, height) ⇒ Object
Resizes the image to width and height using a cubic-bspline filter and yields the new image.
70 71 |
# File 'lib/image_science.rb', line 70 def resize(width, height) # :yields: image end |
#save(path, jpeg_quality = JPEG_QUALITYSUPERB) ⇒ Object
Saves the image out to path. Changing the file extension will convert the file type to the appropriate format.
60 61 62 |
# File 'lib/image_science.rb', line 60 def save(path, jpeg_quality = JPEG_QUALITYSUPERB) save_with_quality(path, jpeg_quality) end |
#save_with_quality(path, jpeg_quality) ⇒ Object
64 |
# File 'lib/image_science.rb', line 64 def save_with_quality(path, jpeg_quality); 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.
77 78 79 80 81 82 83 84 |
# File 'lib/image_science.rb', line 77 def thumbnail(size) # :yields: image w, h = width, height scale = size.to_f / (w > h ? w : h) self.resize((w * scale).to_i, (h * scale).to_i) do |image| yield image end end |
#width ⇒ Object
Returns the width of the image, in pixels.
49 |
# File 'lib/image_science.rb', line 49 def width; end |
#with_crop(left, top, right, bottom) ⇒ Object
Crops an image to left, top, right, and bottom and then yields the new image.
43 44 |
# File 'lib/image_science.rb', line 43 def with_crop(left, top, right, bottom) # :yields: image end |