axe312ger / metalsmith-sharp

Flexible sharp integration for Metalsmith.
10 stars 9 forks source link

How to use resize method with custom options #95

Closed SDaron closed 5 years ago

SDaron commented 5 years ago

I'm trying without success to use the resize method with custom options. This version is just ignored:

{
  "name": "resize",
  "args": [200,200,{
      "fit":"inside",
      "withoutEnlargement":true 
    }
  ]
}

And with an object in args I receive the following error:

Expected integer between 1 and 16383 for width but received [object Object] of type object

{
  "name": "resize",
  "args": [
    {
      "width":200,
      "height":200,
      "fit":"inside",
      "withoutEnlargement":true 
    }
  ]
}

So it seems sharp doesn't accept an object, however, according to the sharp documentation, this should be acceptable set of options. How can I set these options so the images are no wider and no higher than 200 pixels, without cropping and no larger than the input image? Looking into your code, it should work so maybe I'm missing something obvious... Thanks for your help.

SDaron commented 5 years ago

Testing this deeply, this error is due to the sharp version in the npm which is 0.17.0 in your latest release instead of 0.21.0. Could you consider updating the sharp version in npm repository to 0.21.0?

axe312ger commented 5 years ago

There have been problems with 0.20.0 of sharp why I didnt't do it back then. Will have a look now :)

axe312ger commented 5 years ago

New release is out. Should be fixed now. Can you confirm?

SDaron commented 5 years ago

Thanks for upgrading, but unfortunately any attempt to upgrade to the version 2.2.0 gives me now a Metalsmith error Metalsmith · failed to require plugin "metalsmith-sharp".

I've tried deleting nodes_modules and with a fresh install without success.

For information I was able to fix the sharp version temporarly using yarn instead of npm and with resolutions:


  "dependencies": {
    "metalsmith-sharp": "^2.1.1",
  },
  "resolutions": {
    "metalsmith-sharp/sharp": "^0.21.1"
  },
axe312ger commented 5 years ago

Ooops! 2.2.1 should fix it :)

SDaron commented 5 years ago

Yes, everything works fine now! Thanks