From 743a95be0f01696530f558e7f4934cc7e57d3ab8 Mon Sep 17 00:00:00 2001 From: David Jones Date: Wed, 26 Nov 2008 11:39:41 +0800 Subject: [PATCH] Adding cropping support to rmagick processor Signed-off-by: rick --- lib/technoweenie/attachment_fu/processors/rmagick_processor.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb b/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb index aa83b294..4cf4b2cf 100644 --- a/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb @@ -42,6 +42,9 @@ def resize_image(img, size) if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum)) size = [size, size] if size.is_a?(Fixnum) 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) else img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) } end