回形针调整大小以适合矩形框

时间:2022-05-28 04:53:55

I have a rectangular image for example 30x800 pixels

我有一个矩形图像,例如30x800像素

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

我如何使用回形针进行缩放以将宽高比保持为100x100像素的图像,边框填充空白区域?

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

例如:http://www.imagemagick.org/Usage/thumbnails/pad_extent.gif

1 个解决方案

#1


46  

  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"}

#1


46  

  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"}