Resize missing.png depending upon style in paperclip

一世执手 提交于 2019-12-06 07:20:13

问题


I'm using Paperclip to upload a image

here my paperclip configuration

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

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

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


回答1:


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'


来源:https://stackoverflow.com/questions/10933050/resize-missing-png-depending-upon-style-in-paperclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!