开发者

Drop shadows using CarrierWave

I am resurrecting a question that was already asked, but does not have an actual answer.

I would like to automatically add simple drop shadows to images I upload using CarrierWave. It doesn't matter to me whether the image manipulation hap开发者_如何转开发pens using RMagick or MiniMagick.

Input file types should be the CarrierWave 'white list' defaults--jpg, jpeg, png, and gif. The saved file type should be png (necessarily, I think).

Thanks


OK, figured it out. Maybe someone else will find this useful.

Inside my CarrierWave Uploader, the pertinent bits:

include CarrierWave::RMagick

process :shadow

def shadow
  manipulate! do |img|
    layers = Magick::ImageList.new
    image = Magick::Image.read(img.filename).first
    shadow = image.clone
    shadow = shadow.shadow(0, 0, 4.0, 0.5)
    shadow = shadow.colorize(1.0, 1.0, 1.0, 'gray25')
    layers << shadow << image
    result = layers.optimize_layers(Magick::MergeLayer)
  end
end

The key for me to get RMagick to work was using the optimize_layers method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜