class ImageScience

Provides a clean and simple API to generate thumbnails using FreeImage as the underlying mechanism.

For more information, see docs.seattlerb.org/image_science

Constants

VERSION

Public Class Methods

with_image() click to toggle source

The top-level image loader opens path and then yields the image.

# File lib/image_science.rb, line 19
  
with_image_from_memory() click to toggle source

The top-level image loader, opens an image from the string data and then yields the image.

# File lib/image_science.rb, line 25
  

Public Instance Methods

cropped_thumbnail(size) { |image| ... } click to toggle source

Creates a square thumbnail of the image cropping the longest edge to match the shortest edge, resizes to size, and yields the new image.

# 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
height() click to toggle source

Returns the height of the image, in pixels.

# File lib/image_science.rb, line 41
  
resize() click to toggle source

Resizes the image to width and height using a cubic-bspline filter and yields the new image.

# File lib/image_science.rb, line 53
  
rotate() click to toggle source

Rotate the image to angle. Limited to 45 degree skewing only.

# File lib/image_science.rb, line 58
  
save() click to toggle source

Saves the image out to path. Changing the file extension will convert the file type to the appropriate format.

# File lib/image_science.rb, line 47
  
thumbnail(size) { |image| ... } click to toggle source

Creates a proportional thumbnail of the image scaled so its longest edge is resized to size and yields the new image.

# 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
width() click to toggle source

Returns the width of the image, in pixels.

# File lib/image_science.rb, line 36
  
with_crop() click to toggle source

Crops an image to left, top, right, and bottom and then yields the new image.

# File lib/image_science.rb, line 31