I am using the graphics magick wrapper in nodejs and am creating square thumbnails using the following code:
var size = {width: 200, height: 200};
gm(sourcePath)
.resize(size.width * 2, (size.height * 2) + '')
.thumbnail(size.width, size.height + '^')
.gravity('center')
.extent(size.width, size.height)
.profile('*')
.write(outputPath, function (error) {
if (error) console.log('Error - ', error);
});
This works nicely, until the size of my thumbnail is bigger that the input image. In this case I would like the thumbnail to be the size prescribed, but for the image to be placed in the center of it rather than resized.
Is there a way to do this with a group of commands or do I have to write some separate logic to determine that?
I ended up using GM directly for this using this command:
gm convert inputPath -resize "200x200>" -gravity center -extent 200x200 outputPath
This will create an image 200x200 with the input image centered in it, they -resize 200x200> part (note the >) means only resize it to be smaller not bigger
The equivalent command using the gm module in node is:
var size = {width: 200, height: 200};
gm(sourcePath)
.resize(size.width, size.height + ">")
.gravity('Center')
.extent(size.width, size.height)
.write(outputPath, function (error) {
if (error) console.log('Error - ', error);
});