Paperclip将图像保存为带有白色背景的jpg

5

我想知道如何使用Paperclip将带有alpha通道的PNG和GIF文件转换为白色背景的JPG格式。

我尝试了这个方法,但它并没有起作用。

has_attached_file( 
  :photo, 
  :whiny => false, 
  :styles => { 
    :medium => ["300x300>", :jpg], 
    :thumb => ["100x100>", :jpg] 
  }, 
  :convert_options => { :all => '-alpha white -background white'}
)

它将文件保存为灰色背景。

2个回答

13

这里是解决方案

has_attached_file :photo,
  :styles => {
    :medium => ["300x300>",:jpg],
    :thumb => ["100x100>", :jpg]
  },
  :convert_options => {
    :all => '-background white -flatten +matte'
  }

它可能未按照您所期望的方式调整图像大小,@Pat McGee的建议对我更有效。 - antpaw
对我来说,@Pat McGee的答案是正确的!当与裁剪/扩展一起使用时,这个问题给我们带来了很多问题。 - Daniel Torres

7

-alpha remove -background white 更好。 white 不是 -alpha 的有效参数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接