Skip to content

Commit

Permalink
Merge pull request EricR#4 from musicglue/graphics_magick
Browse files Browse the repository at this point in the history
add support for graphics magick with some DCI (guyboertje)
  • Loading branch information
EricR committed Jul 31, 2012
2 parents 79e093f + 875491f commit 71a3df0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions lib/image_sorcery.rb
@@ -1,4 +1,5 @@
require 'subexec'
require 'gm_support'

class Sorcery
def initialize(file)
Expand Down Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions 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

0 comments on commit 71a3df0

Please sign in to comment.