我正在将carrierwave上传程序转换为使用Cloudinary。我有几个这样的方法,它们以Cloudinary格式输出散列,但不幸的是,在版本块中,您无法访问外部方法。我想知道对于cloudinary来说,最好的方法是什么,或者它是否可能。
def custom_crop
if model.cropping?
cloudinary_transformation({x: model.crop_x.to_i,
y: model.crop_y.to_i,
width: model.crop_w.to_i,
height: model.crop_h.to_i,
crop: :crop})
end
end
def watermark
if model.respond_to?(:watermarking?) && model.watermarking?
cloudinary_transformation({overlay: "watermark_x8b0vp",
gravity: :south_east,
x: 0,
y: 106})
end
end理想情况下,我想运行的代码是这样的:
version :cropped_original do
process :custom_crop
process :watermark
resize_to_fill(81, 50, :center)
end发布于 2013-03-26 23:13:38
您可以从process方法返回所需的转换。但是,在这种情况下,您可能希望将它们链接起来。您可以按如下方式执行此操作:
def custom_crop_and_watermark
transformation = []
if model.cropping?
transformation << {x: model.crop_x.to_i,
y: model.crop_y.to_i,
width: model.crop_w.to_i,
height: model.crop_h.to_i,
crop: :crop}
end
if model.respond_to?(:watermarking?) && model.watermarking?
transformation << {overlay: "watermark_x8b0vp", gravity: :south_east, x: 0, y: 106}
end
{:transformation=>transformation}
endhttps://stackoverflow.com/questions/15621347
复制相似问题