class Teaas::Marquee

Public Class Methods

_marquee_animated_image(original_img, options) click to toggle source
# File lib/teaas/marquee.rb, line 26
def self._marquee_animated_image(original_img, options)
  img_width = original_img[0].columns
  img_height = original_img[0].rows
  if img_height > img_width
    crop = true && options[:crop]
    img_height = img_width
  else
    crop = false
  end

  original_img_list = Magick::ImageList.new
  original_img.each { |img| original_img_list << img }

  original_img_list = original_img_list.coalesce

  frames = original_img.length
  marquee_image = Magick::ImageList.new

  original_img_list.each_with_index do |img, i|
    img.crop!(Magick::CenterGravity, img_width, img_width) if crop
    img.dispose = Magick::BackgroundDispose
    roller = _roller(options)
    marquee_image << roller.roll(
      img,
      :img_width => img_width,
      :img_height => img_height,
      :frame => i,
      :total_frames => frames,
      :reverse => options[:reverse],
    )
  end

  marquee_image
end
_marquee_static_image(original_img, options) click to toggle source
# File lib/teaas/marquee.rb, line 61
def self._marquee_static_image(original_img, options)
  marquee_image = Magick::ImageList.new
  img = Teaas::Helper.prepare_for_animation(original_img)

  img_width = img.columns
  img_height = img.rows

  if (img_height > img_width) && options[:crop]
    img.crop_resized!(img_width, img_width, Magick::CenterGravity)
    img_height = img_width
  end

  5.times do |i|
    roller = _roller(options)
    marquee_image << roller.roll(
      img,
      :img_width => img_width,
      :img_height => img_height,
      :frame => i,
      :total_frames => 5,
      :reverse => options[:reverse],
    )
  end

  marquee_image
end
_roller(options) click to toggle source
# File lib/teaas/marquee.rb, line 88
def self._roller(options)
  if options[:horizontal]
    Teaas::HorizontalRoller
  else
    Teaas::VerticalRoller
  end
end
marquee(original_img, options = {}) click to toggle source

Takes in an image, rolls it 20%, 40%, 60%, and 80%, then returns an animated marquee image. Best when used with {Teaas::Turboize.turbo} to generate multiple marquee speeds.

@param original_img [Array] An array of [Magick::ImageList]s @return [Magick::ImageList] The marquee image

# File lib/teaas/marquee.rb, line 8
def self.marquee(original_img, options = {})
  if Helper.animated_gif?(original_img)
    _marquee_animated_image(original_img, options)
  else
    _marquee_static_image(original_img, options)
  end
end
marquee_from_file(path, options = {}) click to toggle source

Takes in an image, rolls it 20%, 40%, 60%, and 80%, then returns an animated marquee image. Best when used with {Teaas::Turboize.turbo} to generate multiple marquee speeds. This is a wrapper around {Teaas::Marquee.marquee}

@param path [String] Path to the image to be created to a marquee image @return [Magick::ImageList] The marquee image

# File lib/teaas/marquee.rb, line 20
def self.marquee_from_file(path, options = {})
  img = Magick::Image.read(path)

  marquee(img, options)
end