Sha256: 6ce95788af48e8f30ea189f0d6795f2fa7d7e6e8433109af403ea87c65215278

Contents?: true

Size: 937 Bytes

Versions: 2

Compression:

Stored size: 937 Bytes

Contents

require 'rmagick'

# Generates an image quilt, ideal for OpenGraph previews.
module Piccle
  class QuiltGenerator
    # Generates a quilt of the given images - up to 9.
    def self.generate_for(photo_paths)
      photo_paths = photo_paths.first(9)
      image_list = Magick::ImageList.new(*photo_paths)
      image_list.montage do |conf|
        conf.border_width = 0
        conf.geometry = "200x200+0+0"
      end
    end

    # Returns a tuple of [width, height] output dimensions. When we stitch a quilt together each square is 200px,
    # but variable numbers of images can lead to quilts of different sizes. OpenGraph tags should include this
    # size information.
    def self.dimensions_for(image_count)
      case image_count
      when 1 then [200, 200]
      when 2 then [400, 200]
      when 3 then [600, 200]
      when 4 then [400, 400]
      when 5..6 then [600, 400]
      else [600, 600]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
piccle-0.1.1.pre lib/piccle/quilt_generator.rb
piccle-0.1.0.rc1 lib/piccle/quilt_generator.rb