【问题标题】:CarrierWave + Cloudinary : chain transformation / crop & scaleCarrierWave + Cloudinary:链式转换/作物和规模
【发布时间】:2014-11-24 08:45:47
【问题描述】:

我无法弄清楚如何进行链式转换。

给定一张图片,我想将其应用“垫裁剪”(example / doc),例如:

cloudinary_transformation transformation: [{ width: 450, height: 450, crop: :pad }]

然后,用户将crop the padded image with JCrop or whatever,所以我将存储crop_x、crop_y和crop_width,然后,我想要这个裁剪图像的多个尺寸,比如200x200:thumb。

我有什么:

# Image version used for cropping
version :large do
  cloudinary_transformation transformation: [{  width: 450, height: 450, crop: :pad }]
end

# A 200x200 version of the cropped image
version :thumb do
  cloudinary_transformation transformation: [{  width: 200, height: 200, crop: :pad }]
  process :crop_thumb
end

def crop_thumb
  return { x:      model.crop_x,
           y:      model.crop_y,
           width:  model.crop_width,
           height: model.crop_width,
           crop:   :pad }
end

但是结果图片的宽度是crop_width而不是200,当然……

【问题讨论】:

    标签: ruby-on-rails carrierwave cloudinary


    【解决方案1】:

    这是我最终做到的:

    version :thumb do
      process :crop_thumb
    end
    
    def crop_thumb
      transformations = []
      transformations << { x: model.crop_x, y: model.crop_y, width: model.crop_width, height: model.crop_width, crop: :crop }
      transformations << { width: 200, height: 200, crop: :fill }
      { transformation: transformations }
    end
    

    【讨论】:

      猜你喜欢
      • 2013-06-17
      • 2015-10-22
      • 2017-10-08
      • 2018-06-23
      • 2013-08-04
      • 2018-05-19
      • 2020-01-22
      • 2015-12-06
      • 2018-06-09
      相关资源
      最近更新 更多