Created
August 16, 2009 20:16
-
-
Save brian-lc/168747 to your computer and use it in GitHub Desktop.
rmagick script that takes an array of images and turns them into photobooth layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'RMagick' | |
| include Magick | |
| class BoothPhoto | |
| IMAGES_ROWS = 2 | |
| BORDER = 5 | |
| attr_reader :row_height, :total_columns | |
| def initialize(photo_uris = []) | |
| collect_photos | |
| # Making the composite image to fit all the photos | |
| @comp = Image.new(total_columns,row_height*IMAGES_ROWS) | |
| add_photos_to_composite | |
| end | |
| def grayscale! | |
| @comp = @comp.quantize(256,GRAYColorspace) | |
| end | |
| def display | |
| @comp.display | |
| end | |
| def save(file_name) | |
| @comp.write(file_name) | |
| end | |
| private | |
| def collect_photos | |
| @photos = [] | |
| @total_columns = 0 | |
| @row_height = 0 | |
| photo_uris.each do |path| | |
| photo = ImageList.new(path) | |
| photo.border!(BORDER, BORDER, "#f0f0ff") #Adding border | |
| @total_columns += photo.columns | |
| if photo.rows > @row_height | |
| @row_height = photo.rows # Getting the maxheight for the row | |
| end | |
| @photos << photo | |
| end | |
| end | |
| def add_photos_to_composite | |
| IMAGES_ROWS.times do |t_row| | |
| offset = 0 | |
| @photos.each do |photo| | |
| @comp.composite!(photo,NorthWestGravity,offset,(@row_height*t_row),AtopCompositeOp) | |
| offset += photo.columns | |
| end | |
| end | |
| end | |
| end | |
| b = BoothPhoto.new(%w(raptorjesus1.jpg raptorjesus2.jpg raptorjesus3.jpg raptorjesus4.jpg)) | |
| b.grayscale!.display | |
| b.save("raptorjesus_composite.jpg") | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment