Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip Resize to fit a rectangular box

I have a rectangular image for example 30x800 pixels

How I can scale it with paperclip to preserve the aspect ratio to a 100x100 pixel image with borders filling the empty area ?

an example : http://www.imagemagick.org/Usage/thumbnails/pad_extent.gif

like image 784
astropanic Avatar asked Apr 28 '10 10:04

astropanic


1 Answers

  has_attached_file :image, :styles => { :thumb => "100x100>" }, 
    :convert_options => {:thumb => "-gravity center -extent 100x100"}

Or with not white background

  has_attached_file :image, :styles => { :thumb => "100x100>" }, 
    :convert_options => {:thumb => "-background red -gravity center -extent 100x100"}
like image 155
Voyta Avatar answered Oct 12 '22 15:10

Voyta