imagemagickimagemagick-convertgm

Image resize using GraphicMagick gm with 'convert' is resulting in inconsistent image


I have been trying to resize images using node.js gm module. It did work for most of the images.But when I try to resize few images, the background color and the text in the image is overlapping.My requirement is to create images of different width's without changing background color.

 gm.command('convert')
                .resize(100)
                .gravity('Center')
                .background('none')
                .extent(100)
                    .toBuffer('JPG', function(err, buffer) {
                        if (err) {
                            next(err);
                        } else {
                            next(null, buffer, key);
                        }
                    });

Below is the original image enter image description here

After resize the image is as below

enter image description here

I did try removing the background and tried adding transparent('white') but this didn't give me expected output. However when I use plain convert command line tool to resize it is working as expected.But my code is using node-js gm module and is deployed in AWS Lambda

Could someone help me in resolving this.


Solution

  • JPG does not support transparency. Try saving your output to PNG or TIFF. You might also try ImageMagick rather than GraphicsMagick. The following works fine for me in command line ImageMagick:

    enter image description here

    convert image.png -resize 100 -background none -gravity center -extent 100 result.png
    


    enter image description here