Adds cropping ability via crop_x,crop_y,crop_width and crop_height
This commit is contained in:
Родитель
4b163938ec
Коммит
96d9d1cf2a
|
@ -92,7 +92,7 @@ module Technoweenie # :nodoc:
|
|||
parent_options = attachment_options || {}
|
||||
# doing these shenanigans so that #attachment_options is available to processors and backends
|
||||
self.attachment_options = options
|
||||
|
||||
|
||||
attr_accessor :thumbnail_resize_options
|
||||
|
||||
attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
|
||||
|
@ -287,7 +287,11 @@ module Technoweenie # :nodoc:
|
|||
thumb.send(:'attributes=', {
|
||||
:content_type => content_type,
|
||||
:filename => thumbnail_name_for(file_name_suffix),
|
||||
:thumbnail_resize_options => size
|
||||
:thumbnail_resize_options => size,
|
||||
:crop_x => crop_x,
|
||||
:crop_y => crop_y,
|
||||
:crop_width => crop_width,
|
||||
:crop_height => crop_height
|
||||
}, false)
|
||||
callback_with_args :before_thumbnail_saved, thumb
|
||||
thumb.save!
|
||||
|
@ -394,7 +398,23 @@ module Technoweenie # :nodoc:
|
|||
def with_image(&block)
|
||||
self.class.with_image(temp_path, &block)
|
||||
end
|
||||
|
||||
def crop_x
|
||||
read_attribute(:crop_x) || 0
|
||||
end
|
||||
|
||||
def crop_y
|
||||
read_attribute(:crop_y) || 0
|
||||
end
|
||||
|
||||
def crop_width
|
||||
read_attribute(:crop_width) || read_attribute(:width)
|
||||
end
|
||||
|
||||
def crop_height
|
||||
read_attribute(:crop_height) || read_attribute(:height)
|
||||
end
|
||||
|
||||
protected
|
||||
# Generates a unique filename for a Tempfile.
|
||||
def random_tempfile_filename
|
||||
|
|
|
@ -44,7 +44,12 @@ module Technoweenie # :nodoc:
|
|||
img.thumbnail!(*size)
|
||||
elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75
|
||||
dimensions = size[1..size.size].split("x")
|
||||
img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
|
||||
if respond_to?(:crop_x)
|
||||
img.crop!(self.crop_x, self.crop_y, self.crop_width, self.crop_height)
|
||||
img.resize!(dimensions[0].to_i, dimensions[1].to_i)
|
||||
else
|
||||
img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
|
||||
end
|
||||
else
|
||||
img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче