使用回形针和现有图像将现有图像调整为新样式RMagick [英] Resize existing images to new style in paperclip & RMagick
问题描述
我一直在使用paperclip上传和自动调整我的Rails应用中的照片,我喜欢它。唯一的问题是每隔一个月,我疯狂的经理决定他想要一个新的尺寸来显示照片。所以我在我的照片模型中添加了一个新的风格,所有都适合新照片,但现有的照片现在是一个问题。现在我开始有多张照片需要处理,我需要一种编程方式来调整现有照片的大小。对于这样的事情,也许有一些回形针技巧?我真的宁愿不必弄清楚RMagick并自己写一个脚本,如果我不需要的话。
I've been using paperclip to upload and auto-resize photos in my Rails app, and I love it. Only problem is about every other month my crazy manager decides he wants a new size to display the photos in. So I add a new style in my Photo model and all is good for new photos, but the pre-existing photos are now a problem. Now that I'm starting to have more than a few photos to deal with I need a programmatic way to resize existing photos. Perhaps there is some paperclip trick for such a thing? I'd really rather not have to figure out RMagick and write a script myself if I don't have to.
推荐答案
你想要Paperclip :: Attachment的重新处理!
方法。请参阅文档。
You want the reprocess!
method of Paperclip::Attachment. See the docs.
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
# Console...
>> User.find_each { |u| u.avatar.reprocess! }
另外,根据重新处理之前的评论!
方法,有一个回形针:刷新Rake任务,这可能更容易。
Also, according to the comments before the reprocess!
method, there's a paperclip:refresh Rake task, which might be easier.
这篇关于使用回形针和现有图像将现有图像调整为新样式RMagick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!