GraphicsMagick for node.js has a method of making thumbnails, written like this in the docs
gm("img.png").thumb(width, height, outName, quality, callback)
For width and height are "minimum value"? http://aheckmann.github.io/gm/docs.html#thumb
The function does not generate an exact size specified. If I input
gm("img.png").thumb(200, 200, ...)
I will have chances to get the following dimensions:
How can I make exact size thumbnails using gm? Please help :(
After making a thumb using the .thumb()
function, use .extent(width, height)
.
In your case, width and height will both be 200. This will paint the picture on a 200x200 canvas centering it automatically if the aspect ratio does not match this size.
I wrote this sample code to create a 200x200 thumbnail from an image that does not meet the aspect ratio requirement without using the .thumb() function. Options is {height: 200, width: 200}
inputImage = inputImage.resize(options.width, options.height, "^"); //^ is the type of resize string
inputImage = inputImage.gravity("Center");
inputImage = inputImage.extent(options.width, options.height);
Input Image - https://www.travelalaska.com/~/media/Images/Travel%20Alaska/Content/HomePage/GlacierBay.jpg
Output Image - https://i.sstatic.net/cARDo.png