Class: Teaas::Turboize

Inherits:
Object
  • Object
show all
Defined in:
lib/teaas/turboize.rb

Class Method Summary collapse

Class Method Details

.turbo(img, resize, speeds = [2, 5, 10, 20, 30, 40], options = {}) ⇒ Array

Takes in an image, a resize parameter, and optionally speeds, and returns an image or images that are sped up or slowed down.

Parameters:

  • img (Magick::ImageList)

    The image to be turboized

  • resize (Integer or Falsey)

    The size of the largest dimension (eg. 32) for the image, or falsey if no resizing should occur

  • speeds (Array) (defaults to: [2, 5, 10, 20, 30, 40])

    An array of Integers that determines the ticks per second for the resulting animated image

Returns:

  • (Array)

    An array of image blobs that match each specified speed



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/teaas/turboize.rb', line 10

def self.turbo(img, resize, speeds=[2, 5, 10, 20, 30, 40], options={})
  speeds = [2, 5, 10, 20, 30, 40] if speeds.nil?
  if !resize.nil? && !resize.empty?
    img = Teaas::Resize.resize(img, resize, options)
  end

  image_blobs = []
  speeds.each do |turbo|
    image_blobs << turboize_individual_image(img, turbo, options).to_blob
  end

  image_blobs
end

.turbo_from_file(path, resize, speeds = [2, 5, 10, 20, 30, 40], options = {}) ⇒ Array

Takes in a path to an image, a resize parameter, and optionally speeds, and returns an image or images that are sped up or slowed down. This method is just a wrapper around turbo

Parameters:

  • path (String)

    The path to the image to be turboized

  • resize

    Truthy if the image should be resized, falsey or nil if it should not

  • speeds (Array) (defaults to: [2, 5, 10, 20, 30, 40])

    An array of Integers that determines the ticks per second for the resulting animated image

Returns:

  • (Array)

    An array of image blobs that match each specified speed



30
31
32
33
34
35
# File 'lib/teaas/turboize.rb', line 30

def self.turbo_from_file(path, resize, speeds=[2, 5, 10, 20, 30, 40], options={})
  img = Magick::ImageList.new
  img.read(path)

  turbo(img, resize, speeds, options)
end

.turboize_individual_image(img, turbo, options = {}) ⇒ Magick::ImageList

Takes in a ‘Magick::ImageList` and adjusts the GIF image delay, ticks per second, and iterations.

Parameters:

  • img (Magick::ImageList)
  • turbo (Integer)

    the ticks per second

Returns:

  • (Magick::ImageList)


42
43
44
45
46
47
# File 'lib/teaas/turboize.rb', line 42

def self.turboize_individual_image(img, turbo, options={})
  img.delay = options[:delay] || 1
  img.ticks_per_second = turbo
  img.iterations = 0
  img
end