Friday, March 07, 2008

image slicing for the hardcore




I'm working on a new version of the Orchive webpage, and after a little clicking with Illustrator and Inkscape, both excellent programs, by the way, I decided that I would rather just write a script to do the slicing for "normal", "hover" and "selected" states of hover buttons.

It turned out to be super easy. I loaded up the image in Gimp, found the X,Y coordinates of the places where I wanted to slice and used RMagick to slice up the image, like this:


#!/usr/bin/ruby

require 'rubygems'
require 'RMagick'
include Magick

normal = ImageList.new("full_normal_state.png")

normal_left = normal.crop(0,274,125,38)
normal_left.write("normal_left.png")

normal_home = normal.crop(125,274,180-125,38)
normal_home.write("normal_home.png")


hover = ImageList.new("full_hover_state.png")

hover_left = hover.crop(0,274,125,38)
hover_left.write("hover_left.png")

hover_home = hover.crop(125,274,180-125,38)
hover_home.write("hover_home.png")


selected = ImageList.new("full_selected_state.png")

selected_left = selected.crop(0,274,125,38)
selected_left.write("selected_left.png")

selected_home = selected.crop(125,274,180-125,38)
selected_home.write("selected_home.png")



So much simpler. And I'm done.