Sunday, August 12, 2007

Build a better skimmer - part 2

We saw in part 1 that we can build a more efficient skimming implementation by using a "film strip" image instead of a bunch of single images. For my example, I built the filmstrip by hand - it sucked. So, I whipped up a quick ruby script for creating a filmstrip of all the jpg's in a directory. If you don't already have RMagick installed, you can find instructions for installing it on the .

The script first crops the images to 160x160, then creates a vertical strip using RMagick's montage functionality.


require 'rubygems'
require 'RMagick'

files = Dir['*.jpg']
imageList = Magick::ImageList.new
numImages = 0
files.each do |file|
unless file == 'filmStrip.jpg'
puts "adding #{file}"
img = Magick::Image.read(file)[0]
img.crop_resized!(160,160)
imageList << img
numImages = numImages + 1
end
end

filmStrip = imageList.montage do
self.geometry = "160x160+0+0"
self.tile = "1x#{numImages}"
end

filmStrip.write('filmStrip.jpg')

0 comments: