我使用Dragonfly在Rails应用程序中生成缩略图图像。将透明PNG转换为JPG时覆盖透明度颜色
我以JPG格式提供所有图片图片。现在的客户端上传透明的PNG文件,像这样的:
http://www.ibanez.co.jp/products/images/eg2010/ART120_TRF_12_02.png
蜻蜓使用RMagick将这些图像转换为JPG。问题是它将PNG图像转换为黑色背景的JPG图像,而我的网站的设计需要白色背景。我试图覆盖它是这样的:
encoded_image = Magick::Image.from_blob(image.data).first
if encoded_image.format.downcase == format
image # do nothing
else
encoded_image.format = format
encoded_image.background_color = "white"
encoded_image.transparent_color = "white"
encoded_image.to_blob
end
但生成的JPG图像仍包含黑色背景。有谁知道如何在转换透明图层时使用白色背景拍摄RMagick?
我知道我可以作为PNG,但是然后图像是10倍大,并且该网站已经很宽带。
工程就像一个魅力!很抱歉,迟到接受。 – 2010-10-17 16:45:23