Ruby On Rails, Design, Simplicity, Web 2.0, Ajax, Mac and Tons of Pizza.

Jan 03

Adding crop capabilities to acts_as_attachment

Posted by Sandro Paganotti in Ruby on Rails - comments are closed digg this add to delicious

Everyone know the plugin: acts_as_attachment created by Rick Olson , that let you manage file uploads and image resizing.

With a very little effort is possible to enhance this plugin by adding crop capabilities that will let you use the following sintax:


  acts_as_attachment :thumbnails => { :thumb => 'crop 91x91'}

To achieve this goal you simply need to add 2 lines of code just after ‘instance_methods.rb’s row 133:


          elsif size.is_a?(String) && size =~ /^crop ([0-9]+)x([0-9]+)$/i
            img.crop_resized($1.to_i, $2.to_i)

Many thanks to Arya who suggested this patch.

Post a comment

Categories:

Tags:

Powered by Mephisto, Valid XHTML 1.1, Valid CSS - Supported by Wave Factory