S
S
Stopy2015-07-27 15:59:47
Node.js
Stopy, 2015-07-27 15:59:47

How to change background color in GraphicsMagick for node.js?

When converting a png image to jpg, the entire transparent background turns black (what an idiot). I searched Google for such a problem, everyone works with the image through the shell console, but I couldn’t find any solution through the module in npm .. Maybe someone knows how to deal with this?
Or can someone suggest an alternative solution? Just pictures before uploading in any case, you need to effectively compress

gm('./upload/'+file.name)
      .quality(cfg.quality)
      .background('white')
      .write("./public/images/"+rand+'.jpg', function (err) {

        fs.unlink('./upload/'+file.name, function(error){
          if (error) res.end('Не удается работать с файлом');
        });
        if (err) {
          res.end('Ошибка при загрузке изображения!');
        } else {
          console.log('Done!');
          res.end(rand+'.jpg');
        }

});

Solution ---->
.background('#FFF')
.mosaic()
.matte()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Shatokhin, 2015-07-27
@Stopy

When converting a png image to jpg, the entire transparent background turns black (what an idiot)

And which one should? jpeg does not support transparency.
It was necessary to look at the manual on GraphicsMagick and use the appropriate method (background) of the module.
gm(image).background("#FFF").stream("jpeg", cb);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question