使用回形针和导轨调整数千张图像大小的最佳方法是什么?



我有一个模型,里面有6张回形针照片(照片1、照片2、照片3、照片4、照片5和照片6)。

因为最近网站的设计发生了变化,我需要调整六张图片上的所有样式。款式有小型、中型和大型。

我的想法是使用过滤前的方法来进行Model.photo1.reprocess!并在模型表中添加一列(例如"reprocess"作为布尔值),以检查是否对其进行了重新处理。

我认为这个想法比使用rake脚本在一次迁移中迁移所有照片并进行下一次部署更有效。

产品控制器

before_filter :check_image_reprocess, :only => [:show]  
def check_image_reprocess
  @product = Product.find(params[:id])
  if @product.reprocess == false
    @product.photo.reprocess! unless @product.photo.nil?
    @product.photo2.reprocess! unless @product.photo2.nil?
    @product.photo3.reprocess! unless @product.photo3.nil?
    @product.photo4.reprocess! unless @product.photo4.nil?
    @product.photo5.reprocess! unless @product.photo5.nil?
    @product.photo6.reprocess! unless @product.photo6.nil?
    @product.update_attributes(:reprocess => true)
  end
end

事实上,它是有效的,但如果对此有任何评论或更好的建议,我们将非常欢迎:)?

提前感谢

这样,经过一周的测试,它可以完美工作!!

享受

最新更新