0

Is there any way to convert a PNG file to 8 bit-depth?

I've tried the following, with some variations (With GraphicsMagic module, gm):

gm(`${IMAGE_PROCESSING_SD}images_thumbs_sd_${i + 1}.png`)
      .bitdepth(8)
      .write(`${IMAGE_PROCESSING_SD}images_thumbs_sd_${i + 1}.png`, () => {
        console.log('finished 8 bit conversion');
      });

But it keeps having 32 bit-depth on some images, 24 in others. Not sure what i'm doing wrong.

Alexander Santos
  • 1,458
  • 11
  • 22

1 Answers1

0

Probably not the best solution, but can still help some people.

Based on this answer, i've used convert (method 4 from answer) to do the work.

I've installed shelljs to aid me with this.

So basically, the solution was something like this:

const shell = require('shelljs');

shell.exec(`convert "${path}" "PNG8:${path}"`);

(To use this, the user needs imagemagick to be installed)

Hope it helps someone in trouble.

Alexander Santos
  • 1,458
  • 11
  • 22