简体   繁体   English

如何将Paperclip图像添加到数据库后调整其大小?

[英]How can I resize a Paperclip image after it has been added to the database?

I've added 2000 pictures to my images table and I'm using the Paperclip plugin to create thumbs. 我已经在我的图像表中添加了2000张图片,而我正在使用Paperclip插件创建拇指。 I'm wondering if there's a way to go through the database and add another :styles element. 我想知道是否有办法通过数据库并添加另一个:styles元素。

For example, when I added the images I had the following in my model: 例如,当我添加图像时,我在模型中有以下内容:

has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }

However, now I want to add a :large attribute and have it applied to every image that's already in my table. 但是,现在我想添加一个:large属性,并将它应用于我表中已经存在的每个图像。 Something like: 就像是:

has_attached_file :image, :styles => { :large => "800x800>", :medium => "300x300>", :thumb => "100x100>" }

Is this possible? 这可能吗? Or would I have to re-add all 2000 pictures? 或者我是否需要重新添加所有2000张照片?

If Paperclip is installed as a plugin, you can do this: 如果Paperclip作为插件安装,您可以这样做:

rake paperclip:refresh:thumbnails CLASS=Screenshot

where Screenshot is the name of the class with the attachment. 其中,屏幕截图是带附件的类的名称。

If it's installed as a gem, do this inside script/console: 如果它是作为gem安装的,请在脚本/控制台中执行此操作:

Screenshot.all.each {|s| s.image.reprocess! }

replacing Screenshot with the appropriate class name 用适当的类名替换屏幕截图

rake paperclip:refresh:thumbnails

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM