无法使用 Paperclip 调整默认图像的大小 [英] Trouble resizing the default image with Paperclip

查看:33
本文介绍了无法使用 Paperclip 调整默认图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够调整我与 Paperclip 一起使用的默认配置文件图像的大小.这是我模型中的代码:

I want to be able to resize the default profile image I use with Paperclip. This is the code in my model:

has_attached_file :photo,
  :styles => {
    :tiny => "25x25#",
    :thumbnail => "100x100#",
    :small  => "150x150>",
    :medium => "300x300>" },
    :default_url => "/images/default.png"

但是,默认图像不会像用户提交的图像那样调整大小.我该怎么做?

However, the default image doesn't get resized like the user submitted images do. How can I do this?

推荐答案

我一直使用的解决方案是指定默认图像的样式:

The solution I've been using is to specify the style for the default image:

has_attached_file :photo,
:styles => {
  :tiny => "25x25#",
  :thumbnail => "100x100#",
  :small  => "150x150>",
  :medium => "300x300>" },
  :default_url => "/images/default_:style.png"

然后为每种样式创建一个默认图像(例如:default_tiny.png 是 25x25px 等...)

Then create a default image for each style (eg: default_tiny.png that is 25x25px, etc...)

希望有所帮助.

这篇关于无法使用 Paperclip 调整默认图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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