Commit 0fabebff by jyurek

Formatting and refactoring transformation_to a bit

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@405 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 632f5ffb
......@@ -79,22 +79,31 @@ module Paperclip
ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
if crop
scale_geometry, scale = if ratio.horizontal? || ratio.square?
[ "%dx" % dst.width, ratio.width ]
else
[ "x%d" % dst.height, ratio.height ]
end
crop_geometry = if ratio.horizontal? || ratio.square?
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
else
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
end
scale_geometry, scale = scaling(dst, ratio)
crop_geometry = cropping(dst, ratio, scale)
else
scale_geometry = dst.to_s
scale_geometry = dst.to_s
end
[ scale_geometry, crop_geometry ]
end
private
def scaling dst, ratio
if ratio.horizontal? || ratio.square?
[ "%dx" % dst.width, ratio.width ]
else
[ "x%d" % dst.height, ratio.height ]
end
end
def cropping dst, ratio, scale
if ratio.horizontal? || ratio.square?
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
else
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
end
end
end
end
......@@ -10,14 +10,14 @@ module Paperclip
# unless specified. Thumbnail creation will raise no errors unless
# +whiny_thumbnails+ is true (which it is, by default.
def initialize file, target_geometry, format = nil, whiny_thumbnails = true
@file = file
@crop = target_geometry[-1,1] == '#'
@target_geometry = Geometry.parse target_geometry
@file = file
@crop = target_geometry[-1,1] == '#'
@target_geometry = Geometry.parse target_geometry
@current_geometry = Geometry.from_file file
@whiny_thumbnails = whiny_thumbnails
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@format = format
end
......
......@@ -15,14 +15,6 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
require File.join(ROOT, 'lib', 'paperclip.rb')
class String
unless methods.include? :pluralize
def pluralize
"#{self}s"
end
end
end
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
......
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