Martijn van Leeuwen
2006-Mar-08 11:33 UTC
[Rails] file_column Cropping -> image offset information
Hello, I had a problem cropping images with file_column. These are my settings: file_column :image, :magick => { :versions => { :thumb => "80x80>", :medium => "150x150>", :square => { :crop => "1:1", :size => "50x50!" } }, :geometry => "400x300>" } With a square thumbnail i had the following problem; the offset information of the images wasn''t reset. The i found this in the rmagick documentation: http://redux.imagemagick.org/RMagick/doc/image1.html#crop_bang -------------------------------------------------------------------------- The |crop| method retains the offset information in the cropped image. This may cause the image to appear to be surrounded by blank or black space when viewed with an external viewer. This only occurs when the image is saved in a format (such as GIF) that saves offset information. To reset the offset data, add |true| as the last argument to |crop|. For example, cropped = img.crop(x, y, width, height, true) You can add |true| as the last argument with any of the three argument list formats described above. -------------------------------------------------------------------------- so adding '',true'' in the file magick_file_column.rb at line 76 solved my problem img = img.crop(::Magick::CenterGravity, [img.columns, w].min, [img.rows, h].min,true)
Martijn van Leeuwen
2006-Mar-09 13:45 UTC
[Rails] file_column Cropping -> image offset information
To complete this wonderfull feature, does anyone have combined this with http://www.speedingrhino.com/cropper.htm Kind Regards, Martijn Tim Case schreef:> Hi Martijn, > > I saw your post regarding the cropping of file_column, and am writing > because I ran into into the same problem myself. I found a short > solution was just to hack up the magick_file_column.rb to do exactly > what I wanted. I wanted to create thumbs and if the aspect ratio > wasn''t 1:1 then I wanted the image to be resized to it''s smallest side > and then cropped. RMagick 1.10.0 has a new method called crop_resized > that handles this perfectly and so I hacked this is in: > > magick_file_column.rb > def resize_image(img, img_options, dest_path) > begin > if img_options[:crop] > w,h = img_options[:crop].split(''x'').map { |x| x.to_f } > img = img.crop_resized(w, h, ::Magick::CenterGravity) > end > > if img_options[:size] > img = img.change_geometry(img_options[:size]) do |c, r, i| > i.resize(c, r) > end > end > ensure > img.write dest_path > File.chmod options[:permissions], dest_path > end > end > > Field in AR active record model which I call using the size of the > image I want rather than the aspect ratio of the crop: > > file_column :image, :magick => {:versions => { > :thumb_center => {:crop => "100x100"}, > > > This seems to be a great way to go > > HTH, > > Tim Case > > >
Peter De Berdt
2006-Mar-10 11:49 UTC
[Rails] file_column Cropping -> image offset information
On 09 Mar 2006, at 14:47, Martijn van Leeuwen wrote:> To complete this wonderfull feature, does anyone have combined this > with > > http://www.speedingrhino.com/cropper.htmSomething like http://pixoh.com/ would be even nicer ;-) Best regards Peter De Berdt
Nithin Reddy
2006-Mar-16 22:16 UTC
[Rails] file_column Cropping -> image offset information
awesome! thanks for the advice. On 3/10/06, Peter De Berdt <peter.de.berdt@pandora.be> wrote:> > On 09 Mar 2006, at 14:47, Martijn van Leeuwen wrote: > > > To complete this wonderfull feature, does anyone have combined this > > with > > > > http://www.speedingrhino.com/cropper.htm > > Something like http://pixoh.com/ would be even nicer ;-) > > Best regards > > Peter De Berdt > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >