Search code examples
image-processinggraphicsmagick

Optimize image with GraphicsMagick


I'm using GraphicsMagick in node.js and I have lots(thousands) that I need to optimize as much as possible. Each one is 250*250 PX and I need to make them 50*50 but this is the easy part.

The problem is how to optimize them too.

By optimizing them I mean make them into jpeg or png(which ever is smaller) and lower the quality(if needed) and other things...

my code so far...

gm(temp_location + file_name)
.gravity('Center')
.extent(50, 50)
.noProfile()
.write(new_location + "s"+name, function (err) {});

so any suggestion on how to make the image any smaller?
any suggestion is appreciated


Solution

  • For JPEG (which is most suitable for photos and other natural images), lowering the quality (which means image quality) will help. Try -quality 40 or less.

    For PNG (which is most suitable for line art), limiting the colors to 254 or fewer and increasing the quality (which actually means compression level) might help. For PNG with a limited number of colors, use a "quality" that is an even multiple of 10, because the second digit specifies the PNG filter method which should be "0" which means no filtering. Try -quality 90.