primitive icon indicating copy to clipboard operation
primitive copied to clipboard

Feature request: transparent background

Open Xe opened this issue 6 years ago • 8 comments

Hi,

I want to use this to generate character sprites for a video game idea. Is there a way to make primitive work with a fully transparent background?

Thanks,

Xe avatar Jul 08 '17 09:07 Xe

Are you using the Mac app? The command line version should already support this.

fogleman avatar Jul 08 '17 19:07 fogleman

@fogleman I use the command line version, but I'm having trouble getting an image with a transparent background. I use a PNG with large areas of transparency, but all of them come out black when passed through primitive.

EDIT: Here's an image you could try - https://i.imgur.com/pbVyVje.png

I tried generating an SVG out of it with the command —

primitive -i test.png -o test.svg -n 100 -m 0 -bg #ffffff

The generated image looks like this - http://svgshare.com/i/3sa.svg

paambaati avatar Nov 15 '17 05:11 paambaati

I am also running into this issue. Transparent regions are output as black.

kanzelm3 avatar Nov 15 '17 17:11 kanzelm3

@paambaati try this command:

primitive -i test.png -o test.svg -n 100 -m 0 -bg #ffffff00

Reading the code in color.go I found out that the input color is intended as one of this:

  • #RGB
  • #RGBA
  • #RRGGBB
  • #RRGGBBAA

AA is the alpha channel value, so if you want it to be transparent just set it to 00

imtoori avatar Nov 21 '17 15:11 imtoori

@Salvatore-Giordano Thanks a ton, that works!

paambaati avatar Nov 21 '17 15:11 paambaati

Still doesn't work for me.

OSX. Input...

beers-color-transparent

Command: ~/code/gopath/bin/primitive -i beers-color-transparent.png -o beers-color-transparent.svg -bg '#ffffff00' -n 500

Output (after conversion to jpg with convert beers-color-transparent.svg svg.jpg)... svg

Alternative output if running ~/code/gopath/bin/primitive -i beers-color-transparent.png -o beers-color-transparent-output.png -bg '#ffffff00' -n 500 to directly generate a PNG... beers-color-transparent-output

Then I realised I had an old version...

$ md5 ~/code/gopath/bin/primitive MD5 (/Users/user/code/gopath/bin/primitive) = 4913fcd77601bfc67dbaa7dfe68f0e54

So I updated...

$ md5 ~/code/gopath/bin/primitive MD5 (/Users/user/code/gopath/bin/primitive) = f3163eec91c5575fb24b547d2279e887

... but no difference observed. I am getting neater backgrounds (at least they are white now!) but 100% opaque ... despite testing both SVG and PNG output. For example...

$ ~/code/gopath/bin/primitive -i beers-color-transparent.png -o beers-color-transparent.svg -m 0 -bg '#ffffff00' -n 500

... zero transparency in SVG, white visible background. Reference output after convert beers-color-transparent.svg svg2.jpg (because Github doesn't support SVG upload)...

svg2

... which is a pretty crappy render (it looks better in Firefox)... screen shot 2017-11-30 at 08 09 30

... but anyway still certainly lacks transparency (tried: Illustrator, Firefox, OSX Finder preview, GIMP).

globalcitizen avatar Nov 30 '17 00:11 globalcitizen

@globalcitizen JPG doesn't do transparency, you need to use PNG. This worked for me on latest master:

go run main.go -i test.png -o out.png -n 100 -bg ffffff00 -v

out

fogleman avatar Nov 30 '17 02:11 fogleman

Thanks.

Yes, I was just uploading JPG because Github doesn't support upload of SVG.

Indeed, that command line does now work for me. No idea what changed there. Weird. Perhaps it is the number of polygons - I note you only used 100 and I was using 500 - as the number increases transparency perhaps tends towards opaque? Perhaps if I set a higher opacity like 100% combined with a higher number of polygons it will work better? Let me test that theory...

Nope. Area 51 has eaten my shell. Thanks 👍

globalcitizen avatar Nov 30 '17 05:11 globalcitizen