5

I'd like to know how to convert png and gif files with alpha channel to jpg with white background with paperclip

I tried this but, it doesn't work

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

It saves the file with the gray background.

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Mathieu
  • 1,175
  • 4
  • 19
  • 34

2 Answers2

13

here the solution

has_attached_file :photo,
  :styles => {
    :medium => ["300x300>",:jpg],
    :thumb => ["100x100>", :jpg]
  },
  :convert_options => {
    :all => '-background white -flatten +matte'
  }
KiT O
  • 867
  • 6
  • 21
Mathieu
  • 1,175
  • 4
  • 19
  • 34
  • It might resize the image not the way you want it to be, the suggestion form @Pat McGee works better for me – antpaw May 15 '14 at 12:08
  • Same for me, @Pat McGee's answer is the correct one! This one brought us a lot of issues when used together with cropping/extending – Daniel Torres Jul 08 '15 at 16:00
7

-alpha remove -background white is preferable. white is not a valid argument for -alpha.

Pat McGee
  • 379
  • 3
  • 9