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.1.3'
Class Method Summary collapse
-
.with_image(path) ⇒ Object
The top-level image loader opens
pathand then yields the image.
Instance Method Summary collapse
-
#composite ⇒ Object
make sure your foreground image is 32 bit and your background image is 24 bit, and both images are the same size note DOES NOT YIELD.
-
#convert_24_bits ⇒ Object
converts the image to 24 bits note DOES NOT YIELD.
-
#convert_32_bits ⇒ Object
converts the image to 32 bits ( including alpha chanel for compisiting) note DOES NOT YIELD.
-
#convert_8_bits ⇒ Object
converts the image to 8 bits , note DOES NOT YIELD.
-
#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.
- #paste ⇒ Object
-
#resize(width, height) ⇒ Object
Resizes the image to
widthandheightusing a cubic-bspline filter and yields the new image. -
#save(path) ⇒ Object
Saves the image out to
path. -
#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.
19 20 |
# File 'lib/image_science.rb', line 19 def self.with_image(path) # :yields: image end |
Instance Method Details
#composite ⇒ Object
make sure your foreground image is 32 bit and your background image is 24 bit, and both images are the same size note DOES NOT YIELD
79 80 |
# File 'lib/image_science.rb', line 79 def composite; end |
#convert_24_bits ⇒ Object
converts the image to 24 bits note DOES NOT YIELD
61 62 |
# File 'lib/image_science.rb', line 61 def convert_24_bits; end |
#convert_32_bits ⇒ Object
converts the image to 32 bits ( including alpha chanel for compisiting) note DOES NOT YIELD
67 68 |
# File 'lib/image_science.rb', line 67 def convert_32_bits; end |
#convert_8_bits ⇒ Object
converts the image to 8 bits , note DOES NOT YIELD
55 56 |
# File 'lib/image_science.rb', line 55 def convert_8_bits; end |
#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.
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/image_science.rb', line 100 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.
37 |
# File 'lib/image_science.rb', line 37 def height; end |
#paste ⇒ Object
73 74 |
# File 'lib/image_science.rb', line 73 def paste; end |
#resize(width, height) ⇒ Object
Resizes the image to width and height using a cubic-bspline filter and yields the new image.
49 50 |
# File 'lib/image_science.rb', line 49 def resize(width, height) # :yields: image end |
#save(path) ⇒ Object
Saves the image out to path. Changing the file extension will convert the file type to the appropriate format.
43 |
# File 'lib/image_science.rb', line 43 def save(path); 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.
86 87 88 89 90 91 92 93 |
# File 'lib/image_science.rb', line 86 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.
32 |
# File 'lib/image_science.rb', line 32 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.
26 27 |
# File 'lib/image_science.rb', line 26 def with_crop(left, top, right, bottom) # :yields: image end |