Graphic magic thumbnails without scaling

I am using a graphical magic shell in nodejs and create 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 well as long as my thumbnail is larger than the input image. In this case, I would like the thumbnail to be at the prescribed size, but so that the image is centered and not resized.

Is there a way to do this with a group of commands, or do I need to write some separate logic to define this?

+3


source to share


1 answer


I ended up using GM for this using this command:

gm convert inputPath -resize "200x200>" -gravity center -extent 200x200 outputPath

      

This will create a 200x200 image with the original image centered in it, they are 200x200> (note>) means its size is no less



Equivalent command using the gm module in node:

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);
  });

      

+13


source







All Articles