Commit 01e50714 by jyurek

Cleaned up modifier handling.

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@421 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent e559ce8e
...@@ -60,7 +60,7 @@ module Paperclip ...@@ -60,7 +60,7 @@ module Paperclip
# Returns the width and height in a format suitable to be passed to Geometry.parse # Returns the width and height in a format suitable to be passed to Geometry.parse
def to_s def to_s
"%dx%d" % [width, height] "%dx%d%s" % [width, height, modifier]
end end
# Same as to_s # Same as to_s
......
...@@ -59,8 +59,8 @@ module Paperclip ...@@ -59,8 +59,8 @@ module Paperclip
# into the thumbnail. # into the thumbnail.
def transformation_command def transformation_command
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?) scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = "-scale #{scale}" trans = "-scale \"#{scale}\""
trans << " -crop #{crop} +repage" if crop trans << " -crop \"#{crop}\" +repage" if crop
trans trans
end end
end end
......
...@@ -59,6 +59,12 @@ class GeometryTest < Test::Unit::TestCase ...@@ -59,6 +59,12 @@ class GeometryTest < Test::Unit::TestCase
end end
end end
should "make sure the modifier gets passed during transformation_to" do
assert @src = Paperclip::Geometry.parse("123x456")
assert @dst = Paperclip::Geometry.parse("123x456>")
assert_equal "123x456>", @src.transformation_to(@dst).to_s
end
should "be generated from a file" do should "be generated from a file" do
file = Dir.glob("/Users/jyurek/Pictures/*.jpg").first file = Dir.glob("/Users/jyurek/Pictures/*.jpg").first
file = File.new(file) file = File.new(file)
......
...@@ -20,11 +20,14 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -20,11 +20,14 @@ class PaperclipTest < Test::Unit::TestCase
assert @dummy.valid? assert @dummy.valid?
assert @dummy.save assert @dummy.save
assert_equal "100x15", `identify -format "%wx%h" #{@dummy.avatar.to_io.path}`.chomp [["100x15", nil],
assert_equal "434x66", `identify -format "%wx%h" #{@dummy.avatar.to_io(:original).path}`.chomp ["434x66", :original],
assert_equal "300x46", `identify -format "%wx%h" #{@dummy.avatar.to_io(:large).path}`.chomp ["300x46", :large],
assert_equal "100x15", `identify -format "%wx%h" #{@dummy.avatar.to_io(:medium).path}`.chomp ["100x15", :medium],
assert_equal "32x32", `identify -format "%wx%h" #{@dummy.avatar.to_io(:thumb).path}`.chomp ["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" #{@dummy.avatar.to_io(style).path}]
assert_equal geo, `#{cmd}`.chomp, cmd
end
saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_io(s).path } saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_io(s).path }
......
...@@ -48,7 +48,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -48,7 +48,7 @@ class ThumbnailTest < Test::Unit::TestCase
end end
should "report its correct current and target geometries" do should "report its correct current and target geometries" do
assert_equal "100x50", @thumb.target_geometry.to_s assert_equal "100x50#", @thumb.target_geometry.to_s
assert_equal "434x66", @thumb.current_geometry.to_s assert_equal "434x66", @thumb.current_geometry.to_s
end end
...@@ -62,7 +62,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -62,7 +62,7 @@ class ThumbnailTest < Test::Unit::TestCase
should "send the right command to convert when sent #make" do should "send the right command to convert when sent #make" do
@thumb.expects(:system).with do |arg| @thumb.expects(:system).with do |arg|
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}"\s+-scale\s+x50\s+-crop\s+100x50\+114\+0\s+\+repage\s+".*?"} arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}"\s+-scale\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
end end
@thumb.make @thumb.make
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment