diff --git a/lib/gm_support.rb b/lib/gm_support.rb new file mode 100644 index 0000000..145488b --- /dev/null +++ b/lib/gm_support.rb @@ -0,0 +1,15 @@ +module GmSupport + def prefix command + "gm #{command}" + end +end + +class Sorcery + class << self + def gm file + instance = new(file) + instance.extend GmSupport + instance + end + end +end diff --git a/lib/image_sorcery.rb b/lib/image_sorcery.rb index ab6487f..1b8b102 100644 --- a/lib/image_sorcery.rb +++ b/lib/image_sorcery.rb @@ -1,4 +1,5 @@ require 'subexec' +require 'gm_support' class Sorcery def initialize(file) @@ -53,6 +54,7 @@ def dimensions private def convert_to_command(tokens) + tokens[0] = prefix(tokens[0]) if respond_to? :prefix tokens.flatten.join("") end diff --git a/spec/image_sorcery_gm_spec.rb b/spec/image_sorcery_gm_spec.rb new file mode 100644 index 0000000..14f6ca7 --- /dev/null +++ b/spec/image_sorcery_gm_spec.rb @@ -0,0 +1,32 @@ +require 'fileutils' +require 'image_sorcery' + +describe "Image Sorcery" do + before :each do + FileUtils.copy "./spec/fixtures/dog.jpeg", "./spec/fixtures/dog-2.jpeg" + @image = Sorcery.gm("./spec/fixtures/dog-2.jpeg") # Who doesn't love dogs? + end + describe "getting the dimensions of an image" do + it "returns a hash of dimensions" do + @image.dimensions.should == {:x => "160", :y => "120"} + end + end + describe "manipulating an image" do + it "resizes an image" do + original_dimensions = @image.dimensions + @image.manipulate!(:resize => "50%") + @image.dimensions.map {|k,v| v.to_i}.should == original_dimensions.map {|k,v| v.to_i/2} + end + end + describe "converting an image" do + it "writes the new image out to a file" do + @image.convert("new_image.png") + File.exists?("new_image.png").should be_true + end + end + describe "identifying an image" do + it "returns a list of layers" do + @image.identify.should include "JPEG 160x120" + end + end +end