furagu / easy-gd

A simplified Node.js wrapper around GD image manipulation library with extra features making your life easier.
MIT License
25 stars 14 forks source link

Alpha channel turns black #4

Closed jacobtomlinson closed 9 years ago

jacobtomlinson commented 9 years ago

Thanks for this library, it's great!

One problem I've found when adding watermarks to PNGs with transparency is that the transparency turns black.

Any ideas on how to fix this?

furagu commented 9 years ago

Hey! Good to hear you liked the library.

Actually it should handle the transparency correctly. So, could you provide some sample files and code? I can take a look and just fix that.

jacobtomlinson commented 9 years ago

Yeah no problem, I'll just get you some example code.

jacobtomlinson commented 9 years ago

Original files

input.png dog_png2414 smiley.png smiley

Code

    var outStream = fs.createWriteStream('/tmp/output.png')
    fs.createReadStream('/tmp/input.png')
        .pipe(gd.watermark('/tmp/smiley.png', {x: 1, y: 0.9}))
        .pipe(outStream)

Result

output.png ea9b0c65c1

jacobtomlinson commented 9 years ago

Any update on this? Thanks!

jacobtomlinson commented 9 years ago

Bump

furagu commented 9 years ago

@jacobtomlinson sorry man, was busy the whole weekend. Will take a look tonight.

jacobtomlinson commented 9 years ago

Awesome thanks!

jacobtomlinson commented 9 years ago

Great thank you very much.

furagu commented 9 years ago

You are welcome! The updated version is already available via npm.

By the way, your smiley.png has a white opaque background, which was kinda confusing :) Anyway, now that works:

var gd = require('./index.js'),
    fs = require('fs')

var outStream = fs.createWriteStream('out.png')

fs.createReadStream('in.png')
    .pipe(gd.watermark( gd.open('in.png').resize({width: 200, height: 200}) ))
    .pipe(gd.watermark('s.png'))
    .pipe(outStream)

out

jacobtomlinson commented 9 years ago

Ah thanks. I just grabbed that smiley off the interwebs for the example, I'm not actually using it.