Skip to content

Instantly share code, notes, and snippets.

@saphes
Last active December 26, 2018 13:57
Show Gist options
  • Save saphes/21182e1c444963879f0b84d31ba3b0fc to your computer and use it in GitHub Desktop.
Save saphes/21182e1c444963879f0b84d31ba3b0fc to your computer and use it in GitHub Desktop.
/*
FIRST: MAKE SURE YOU HAVE IMAGEMAGICK INSTALLED
In this case, the variable imageBuffer represents a buffer containing image data to be processed.
It seems to work with most image filetypes, but I've had the most luck with PNG and JPEG.
The second parameter of the .in() method, in this case, is '50x50%', which means the source image will be scaled to 50% of its original size.
This can be changed to virtually anything, and you can even remove the % for pixel measurements.
The first parameter of the .toBuffer() method has to do with output format. Not sure what you'd put there for JPEG. It's probably 'JPEG' or 'JPG'.
If the module's author was feeling especially fancy when they wrote it, it might be something unnecessarily complicated like JFIF.
I'm glad that after days of trying, I managed to find a way to do this. Enjoy.
*/
const gm = require('gm').subClass({imageMagick: true});
// remember to define imageBuffer before passing it on to gm
gm(imageBuffer).in('-liquid-rescale', '50x50%').toBuffer('PNG', (err, buffer) => {
// buffer can be used here
});
@Hobette
Copy link

Hobette commented Dec 26, 2018

ba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment