🐛 [storage-resize-images] Consider allowing user configurable parameter for sharp resize.fit?
What feature would you like to see?
As a user wishing to resize images sometimes I may want to choose a different resize method or "fit" parameter. https://github.com/firebase/extensions/blob/46636f45645180108fab7ef93e881b4416c26245/storage-resize-images/functions/src/resize-image.ts#L32
How would you use it?
If I can set fit to "outside" then my front-end app is guaranteed that the resized image will provide a consistent output for users, and I don't have to fork this repo and upload this stuff to my own firebase project.
+1 I was also looking for this option, to crop the image instead of fitting it inside.
I would extend the functionality for IMG_SIZES to be able to optionally provide the fit inside, ex: IMG_SIZES=400x320:cover or something like that.
This should be possible now with Sharp constructor options for resizing images field, let us know if you're still having any issues.
@pr-Mais No, it is not. There is no option for that in the sharp options. And even if there would be, it would not work because the fit value is hardcoded to inside on the resize method. See: https://github.com/firebase/extensions/blob/next/storage-resize-images/functions/src/resize-image.ts#L50
This is still not resolved.
Thanks for pointing out the exact issue, I will re-open this and investigate.
@pr-Mais btw, the default fit value for sharp resize is cover which is the most common use case when resizing images. See: https://sharp.pixelplumbing.com/api-resize#resize. I am not sure why for this extension it was chosen to be inside which will not keep the exact sizes as configured, but will be useful to have a way to configure that per each image size and also to change the default fit value to cover.
@pr-Mais also would be good to consider other resize options per image. So we can provide a json object as the 3rd value for each image size. Ex: IMG_SIZES=400x320:{"fit":"contain","position":"right top"}
The Sharp constructor options for resizing images does not accept any parameters to control fitting, or any other parameters for that matter. It all compiles to an error. {fit: "inside"}
Is there a syntax error in your code?
Detailed stack trace: SyntaxError: Unexpected token f in JSON at position 2
at JSON.parse (<anonymous>)
at allowAnimated (/workspace/lib/config.js:39:22)
at Object.<anonymous> (/workspace/lib/config.js:59:15)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at Object.<anonymous> (/workspace/lib/resize-image.js:9:18)
My app no longer works as expected since the default fit options have changed after updating the extension. I need quite an urgent solution to be able to set the fit option to "inside"
Hi @big-brave-pete, the options should be passed as a JSON string, so please use {"fit": "inside"} and it should work.
Hi @big-brave-pete, the options should be passed as a JSON string, so please use
{"fit": "inside"}and it should work.
I've tried the option. (Trying it earlier today it didn't work however) When saving the changes the compiler did return an error message, but it seems to work. Also, updating the configuration the editor doesn't always want to start the save process. Sometimes I need to navigate away from the settings and come back to it before the save function will work.
Thanks for the quick response!
@big-brave-pete you mean the Firebase Console? hope the issue is solved now? let me know.