Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to crop & fill with Paperclip (or RMagick)?

I upload a photo, it is a rectangle. How Can I get it resized and filled to a square ?

I mean when the photo is horizontal positioned it should have above and under it, two white fields (for keeping the shape of a square) and when it is vertically, it should have two white fields on the sides of the photo.

When I used PHP, a have used this http://www.verot.net/php_class_upload_samples.htm

Have a look at the

100x150, keeping ratio, filling top and bottom

example

I'm using Paperclip with RoR. How is the best way to do that ?

like image 760
astropanic Avatar asked Jul 22 '09 17:07

astropanic


People also ask

How do I Crop a picture using my keyboard?

[Alt] J P V C (note that you don't hold down the alt key, you click it like a key).


1 Answers

Here's what I used on a rails 3 app w/ paperclip. I used the following ImageMagick options to make it centered: background, compose, gravity and extent. I'm using the mini_magick processor.

has_attached_file :image,
  :styles => { :large => ["855x570>", :jpg], :medium => ["432x288>", :jpg], :small => ["276x184>", :jpg], :tiny => ["195x130>", :jpg] },
  :processor => "mini_magick",
  :convert_options => {
    :medium => "-background white -compose Copy -gravity center -extent 432x288",
    :small => "-background white -compose Copy -gravity center -extent 276x184",
    :tiny => "-background white -compose Copy -gravity center -extent 195x130"
  }
like image 159
danlee Avatar answered Sep 27 '22 17:09

danlee