在Carrierwave中重新处理不同版本的图像 [英] Reprocessing images of different versions in Carrierwave
本文介绍了在Carrierwave中重新处理不同版本的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Carrierwave,我使用以下几行创建了3个版本的化身-原始图像,small_thumb和large_thumb:
Using Carrierwave, I created 3 versions of an avatar - an original, a small_thumb and a large_thumb using the following lines:
process :resize_to_limit => [400, 400]
version :big_thumb do
process :resize_to_limit => [80, 80]
end
version :small_thumb do
process :resize_to_limit => [50, 50]
end
我在AvatarUploader类中添加了一个附加方法:
I added an additional method in my AvatarUploader class:
def reprocess(x,y,w,h)
manipulate! do |img|
img.crop(x.to_i, y.to_i, w.to_i, h.to_i, true)
end
resize_to_limit(180,180)
end
在执行更新后在我的模型中调用:
which is called in my model after an update is performed:
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
after_update :reprocess_image, :if => :cropping?
def cropping?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
private
def reprocess_image
image.reprocess(crop_x,crop_y,crop_w,crop_h)
end
我设法裁剪并调整了原始版本的大小,但似乎无法同时更新2个缩略图.我尝试了几种不同的方法,都无济于事.
I have managed to crop and resize the original version, but I can't seem to update the 2 thumbnails along with it. I tried a few different techniques to no avail.
有什么建议吗?
推荐答案
尝试
image.recreate_versions!
对不起,在公共汽车上.我无法解释这一点.
Sorry, on the bus. I can't expound on that.
这篇关于在Carrierwave中重新处理不同版本的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文