Skip to content

Loading…

background('none') leads to a white background #245

Closed
PEM-- opened this Issue · 11 comments

2 participants

@PEM--

Don't know where to start on helping.

I want to take an SVG with a transparent background and save it as a PNG with the same transparent background.

If I use the following command line everything works as expected:

gm convert -background none icon.svg icon.png

But, if I use the following CS line, the transparent property is lost (same thing in JS):

gm('icon.svg').background('none').write 'icon.png', (err) -> console.log err if err

No error is returned so it looks like the background command/property is there, but it doesn't do what it is supposed to. It ends up with a plain white background.

@jonathanong

use DEBUG=gm and see what command actually gets executed

@PEM--

Hi Jonathan. This may be a dumb question but where do I put this DEBUG=gm assertion? Before calling the REPL?

@jonathanong

in a test script. https://github.com/visionmedia/debug very useful for debugging :D

@PEM--

Didn't know this one. I'm checking it. Thx.

@PEM--

Here's the command line generated:

gm "convert" "icon.svg" "-background" "none" "icon.png"
@PEM--

OK, I get it. The SVG image is loaded by GM before the background is set. Thus, the SVG is rendered on a white background and the real background directive has no impact.

Doing this, works fine:

gm "convert" "-background" "none" "icon.svg" "icon.png"

Doing that, fails (the gm module's way):

gm "convert" "icon.svg" "-background" "none" "icon.png"

In essence, the background directive should be called before the SVG is loaded. It's an in directive.

Do you have any clue how I should proceed?

@jonathanong

okay looks like "background" is a setting, so should be moved to the front: http://www.imagemagick.org/script/command-line-processing.php

@jonathanong

if you want to make a PR, it's a matter of switching the function from .out to .in: https://github.com/aheckmann/gm/blob/master/lib/args.js#L1046 + a test

otherwise, i'll get to it eventually

@PEM--

I'm currently at work but I'm eager on contributing back to this project. If you allow me, I would be glad to make the PR and its tests. Thanks to your hint, I should be able to do it on my own.

@PEM--

Jonathan, I've performed the updates. It works nicely and the tests have been updated accordingly. I've done my modification on the master branch. How do I push them as I'm not among the declared contributors?

@jonathanong

merged. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.