我无法弄清楚如何进行连锁转型。
给定一张图片,我想将它应用于垫片作物中。 (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,当然......
答案 0 :(得分:2)
以下是我最终的表现:
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