问题
I use CarrierWave to generate versions (thumbnails with different sizes) and also to add a watermark on each versions.
I have currently manage to apply the watermark for each thumbnails but I would like to add it on the original image to.
Here is what I tried:
def watermark
manipulate! do |img|
watermark = Magick::Image.read(Rails.root.join('app/assets/images/watermark_512.png')).first
img = img.composite(watermark, Magick::CenterGravity, Magick::OverCompositeOp)
end
end
version :original do
process :watermark
end
version :thumb_512 do
process :resize_to_fit => [512, 512]
process :watermark
end
version :thumb_256 do
process :resize_to_fit => [256, 256]
process :watermark
end
But this does not work. However I tried to simply add
process :watermark
outside any "version" block but all it does is adding twice the watermark on my thumbnails.
回答1:
You can use store
callbacks provided by CarrierWave in your uploader class like this
class SomeUploader < CarrierWave::Uploader::Base
# Your code ...
before :store, :watermark_method
def watermark_method(*args)
# watermark it!
end
end
来源:https://stackoverflow.com/questions/13903737/how-to-process-only-on-original-image-file-using-carrierwave