Commit d1920aab by Jon Yurek

Actually do the auto_orientation

parent f2320979
...@@ -6,8 +6,8 @@ module Paperclip ...@@ -6,8 +6,8 @@ module Paperclip
end end
def make def make
GeometryParser.new(geometry_string.strip).make || geometry = GeometryParser.new(geometry_string.strip).make
raise(Errors::NotIdentifiedByImageMagickError.new) geometry || raise(Errors::NotIdentifiedByImageMagickError.new)
end end
private private
......
...@@ -17,7 +17,7 @@ module Paperclip ...@@ -17,7 +17,7 @@ module Paperclip
# :expected_outcodes -> An array of integers that defines the expected exit codes # :expected_outcodes -> An array of integers that defines the expected exit codes
# of the binary. Defaults to [0]. # of the binary. Defaults to [0].
# #
# :log_command -> Log the command being run when set to true (defaults to false). # :log_command -> Log the command being run when set to true (defaults to true).
# This will only log if logging in general is set to true as well. # This will only log if logging in general is set to true as well.
# #
# :swallow_stderr -> Set to true if you don't care what happens on STDERR. # :swallow_stderr -> Set to true if you don't care what happens on STDERR.
......
...@@ -39,6 +39,9 @@ module Paperclip ...@@ -39,6 +39,9 @@ module Paperclip
@format = options[:format] @format = options[:format]
@animated = options[:animated].nil? ? true : options[:animated] @animated = options[:animated].nil? ? true : options[:animated]
@auto_orient = options[:auto_orient].nil? ? true : options[:auto_orient] @auto_orient = options[:auto_orient].nil? ? true : options[:auto_orient]
if @auto_orient && @current_geometry.respond_to?(:auto_orient)
@current_geometry.auto_orient
end
@source_file_options = @source_file_options.split(/\s+/) if @source_file_options.respond_to?(:split) @source_file_options = @source_file_options.split(/\s+/) if @source_file_options.respond_to?(:split)
@convert_options = @convert_options.split(/\s+/) if @convert_options.respond_to?(:split) @convert_options = @convert_options.split(/\s+/) if @convert_options.respond_to?(:split)
......
...@@ -139,6 +139,14 @@ class GeometryTest < Test::Unit::TestCase ...@@ -139,6 +139,14 @@ class GeometryTest < Test::Unit::TestCase
assert_equal 434, @geo.width assert_equal 434, @geo.width
end end
should 'calculate an EXIF-rotated image dimensions from a path' do
file = fixture_file("rotated.jpg")
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
@geo.auto_orient
assert_equal 300, @geo.height
assert_equal 200, @geo.width
end
should "not generate from a bad file" do should "not generate from a bad file" do
file = "/home/This File Does Not Exist.omg" file = "/home/This File Does Not Exist.omg"
assert_raise(Paperclip::Errors::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) } assert_raise(Paperclip::Errors::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
......
...@@ -128,6 +128,16 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -128,6 +128,16 @@ class ThumbnailTest < Test::Unit::TestCase
end end
end end
should 'properly crop a EXIF-rotated image' do
file = File.new(fixture_file('rotated.jpg'))
thumb = Paperclip::Thumbnail.new(file, :geometry => "50x50#")
output_file = thumb.make
command = Cocaine::CommandLine.new("identify", "-format %wx%h :file")
assert_equal "50x50", command.run(:file => output_file.path).strip
end
context "being thumbnailed with source file options set" do context "being thumbnailed with source file options set" do
setup do setup do
@thumb = Paperclip::Thumbnail.new(@file, @thumb = Paperclip::Thumbnail.new(@file,
...@@ -306,62 +316,6 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -306,62 +316,6 @@ class ThumbnailTest < Test::Unit::TestCase
end end
end end
context "An image with exif orientation" do
setup do
@file = File.new(fixture_file("rotated.jpg"), 'rb')
end
teardown { @file.close }
context "With :auto_orient => false" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50", :auto_orient => false)
end
should "send the right command to convert when sent #make" do
@thumb.expects(:convert).with do |*arg|
arg[0] == ':source -resize "100x50" :dest' &&
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
end
@thumb.make
end
should "create the thumbnail when sent #make" do
dst = @thumb.make
assert_match /75x50/, `identify "#{dst.path}"`
end
should "not touch the orientation information" do
dst = @thumb.make
assert_match /exif:Orientation=6/, `identify -format "%[EXIF:*]" "#{dst.path}"`
end
end
context "Without :auto_orient => false" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50")
end
should "send the right command to convert when sent #make" do
@thumb.expects(:convert).with do |*arg|
arg[0] == ':source -auto-orient -resize "100x50" :dest' &&
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
end
@thumb.make
end
should "create the thumbnail when sent #make" do
dst = @thumb.make
assert_match /33x50/, `identify "#{dst.path}"`
end
should "remove the orientation information" do
dst = @thumb.make
assert_match /exif:Orientation=1/, `identify -format "%[EXIF:*]" "#{dst.path}"`
end
end
end
context "A multipage PDF" do context "A multipage PDF" do
setup do setup do
@file = File.new(fixture_file("twopage.pdf"), 'rb') @file = File.new(fixture_file("twopage.pdf"), 'rb')
......
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