回形针调整大小以适合矩形框 [英] Paperclip Resize to fit a rectangular box

查看:146
本文介绍了回形针调整大小以适合矩形框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a rectangular image for example 30x800 pixels

如何使用paperclip缩放它以保持宽高比为100x100像素图像,边框填充空白区域?

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

一个例子: http:/ /www.imagemagick.org/Usage/thumbnails/pad_extent.gif

推荐答案

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

或者没有白色背景

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

这篇关于回形针调整大小以适合矩形框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆