devongovett / png-stream

A streaming PNG encoder and decoder
29 stars 4 forks source link

convert png to jpg do not get the right picture #2

Closed ChitaGideon closed 8 years ago

ChitaGideon commented 8 years ago

the png is this:

test image

code:

  fs.createReadStream(file)
  .pipe(new PNGDecoder)
  //.pipe(new neuquant.Stream)
  .pipe(new JPEGEncoder)
  .pipe(fs.createWriteStream('indexed.jpg'));

and the convert result : result image

devongovett commented 8 years ago

If the png has an alpha channel, that could happen. You should try putting a color transform to rgb in the middle.

ChitaGideon commented 8 years ago

you are right change my code to

  fs.createReadStream(file)
  .pipe(new PNGDecoder)
  .pipe(new ColorTransform('rgb'))
  .pipe(new JPEGEncoder)
  .pipe(fs.createWriteStream('indexed.jpg'));

anything make sence