Domanda

Hello I want to make thumbnails without upscaling. I use this one code:

gm(__dirname + '/images/Lighthouse.jpg')
.noProfile()
.gravity('Center')
.thumb('1920', '1280>', __dirname + '/images/thumb.jpg', 90, function (err){
    if (err) { console.log(err); }
});

But it still upscale result image. I try another way:

gm(__dirname + '/images/Lighthouse.jpg')
.noProfile()
.gravity('Center')
.resize('1920', '1280' + ">")
.quality(90)
.crop('1920', '1280')
.write(__dirname + '/images/resize.jpg', function (err) {
    if (err) { console.log(err); }
});

It really prevent upsculing, but, i can't pass another option - "^" in resize because without it i get wrong result of thumbnail. You can compare it on:

gm(__dirname + '/images/Lighthouse.jpg')
.noProfile()
.gravity('Center')
.thumb('320', '480', __dirname + '/images/thumb.jpg', 90, function (err){
    if (err) { console.log(err); }
});

gm(__dirname + '/images/Lighthouse.jpg')
.noProfile()
.gravity('Center')
.resize('320', '480' + "^")
.quality(90)
.crop('320', '480')
.write(__dirname + '/images/resize.jpg', function (err) {
    if (err) { console.log(err); }
});

This code return similar result, but upscale image. Is there any way to provide "^>" options together? Thanks.

P.S. Seems like thumbinal method a little bit blurred than resize/crop.

È stato utile?

Soluzione

The following should do the trick:

gm(__dirname + '/images/Lighthouse.jpg')
  //...
  .resize('320', '480', "^>")
  // ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top