2014-09-29 49 views
1

我無法弄清楚如何進行連鎖轉型。CarrierWave + Cloudinary:連鎖轉型/作物和規模

鑑於我想申請這一個 '墊作物' 的圖像(example/doc)所以像:

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

然後,用戶將crop the padded image with JCrop or whatever,所以我將存儲crop_xcrop_ycrop_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,當然...

回答

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