Paperclip save images as jpg with white background
Asked Answered
D

2

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.

Deadpan answered 1/2, 2010 at 19:25 Comment(0)
C
7

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

Candescent answered 29/10, 2013 at 20:55 Comment(0)
D
13

here the solution

has_attached_file :photo,
  :styles => {
    :medium => ["300x300>",:jpg],
    :thumb => ["100x100>", :jpg]
  },
  :convert_options => {
    :all => '-background white -flatten +matte'
  }
Deadpan answered 3/2, 2010 at 18:0 Comment(2)
It might resize the image not the way you want it to be, the suggestion form @Pat McGee works better for meJenine
Same for me, @Pat McGee's answer is the correct one! This one brought us a lot of issues when used together with cropping/extendingBelongings
C
7

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

Candescent answered 29/10, 2013 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.