根据回形针中的样式调整missing.png的大小 [英] Resize missing.png depending upon style in paperclip

查看:45
本文介绍了根据回形针中的样式调整missing.png的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Paperclip 上传图片

I'm using Paperclip to upload a image

这里是我的回形针配置

has_attached_file :avatar, 
                    :path => ":rails_root/public/users/:id/avatar/:style/avatar.jpg",
                    :url => "/users/:id/avatar/:style/avatar.jpg",
                    :default_url => "/missing/users/:style/missing.png",
                    :styles => {"47x47" => "47x47", "228x228" => "228x228","185x176"=>"185x176","pitch_planner"=>"262x129!"},
                    :convert_options => {"47x47" => "-background black -gravity center -extent 47x47",
                      "228x228" => "-background black -gravity center -extent 228x228","185x176" => "-background black -gravity center -extent 185x176"}

现在如果我想根据样式"生成一个大小调整为missing.png的图像如何在回形针中实现这一点

Now what if I want is to generate a resize image of missing.png depending upon the "style" How to achieve this in paperclip

一种手动​​调整图像大小并将其存储在文件夹 pitch_planner 或您想要调整大小的样式的一种方法

One way to do it resize the image manually and store it inside folder pitch_planner or what ever styles you want to resize for

是否可以通过回形针以编程方式完成

can it be done in programmatically through paperclip

推荐答案

不能使用回形针,但您可以覆盖查找默认图像的方法,如果尚未存在,则使用 image magick 创建它.

Not with paperclip, but you could overwrite the method that looks for the default image, and use image magick to create it if not already present.

img = Magick::Image::read(default_image).first
img.resize_to_fit(75, 75)
img.write 'path'

这篇关于根据回形针中的样式调整missing.png的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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