3
votes

I have an place where i upload an SVG file using paperclip, and get converted it to PNG with the same dimension. When it gets converted, my final PNG output was having white background, when my uploaded SVG have transparent background.

Tried with paperclip convert_options, but it was not providing proper output, such as the image have some pixels of white all over the borders.

Example, trans << "-fuzz 0% -transparent 'rgb(255,255,255)'"

Finaly got it working with an after_save method which uses inkscape to convert my SVG to PNG and replace the PNG generated by paperclip.

Example, inkscape --export-png=OUTPUT.png INPUT.svg

But this looks like a double work, to use paperclip(IM) and also inkscape. So, is there any other way to get proper PNG using paperclip with transparent background when my uploaded SVG has transparent background.

Thanks in advance,

2

2 Answers

3
votes

I fixed issue by Paperclip 'source_file_options' option:

has_attached_file :icon,
                    source_file_options:  { all: '-background transparent' },
                    styles: {
                      :"200" => ["200", :png],
                    }
2
votes

Finaly got the issue sorted myself... :) It was my bad, as i didn't see "-layers merge" getting adding to my paperclip command from initializers...

Paperclip::Attachment.default_options[:convert_options] = { :all => '-layers merge' }

Finally got it worked with paperclip(IM) itself... Hope it will help someone..... :)