Reputation: 31
I am using the Firebase extension storage-resize-images to resize images, but larger images are being cropped to exactly the resized dimensions (i.e., 3000x3000px). There seems to be no scaling based on image ratio. This only occurs when the image is larger than the specified resize parameter.
Am I missing something? I see nothing in the documentation about cropping. Could the resize extension require some metadata that's missing from the images?
The documentation reads to me that scaling and maintaining ration should be automatic:
For example, say that you specify a max width of 200px and a max height of 100px. You upload an image that is 480px wide by 640px high, which means a 0.75 aspect ratio. The final resized image will be 75px wide by 100px high to maintain the aspect ratio while also being at or under both of your maximum specified dimensions.
My extension setup:
Sizes of resized images 1000x1000,2000x2000,3000x3000
Deletion of original file on_success
Make resized images public (Optional) true
Cloud Storage path for resized images (Optional) Parameter not set
Paths that contain images you want to resize (Optional) Parameter not set
List of absolute paths not included for resized images (Optional) Parameter not set
Cloud Storage path for failed images (Optional) Parameter not set
Cache-Control header for resized images (Optional) Parameter not set
Convert image to preferred types webp
Output options for selected formats (Optional) {"webp": { "quality": 100 }}
Sharp constructor options for resizing images (Optional) Parameter not set
GIF and WEBP animated option (Optional) true
Cloud Function memory 2048
Backfill existing images false
I have tried uploading files multiple times, of various sizes. I have compared the source file on my machine with the image stored in firebase (via Firebase console). Looking at the logs for the extension, I don't see any errors.
Upvotes: 3
Views: 502
Reputation: 17976
As explained by @Rhytmus, you have to set this in your extension configuration, at the "Sharp constructor options for resizing images" parameter:
{ "fit":"inside" }
IMPORTANT: In my case this configuration change failed every time. I finally had to uninstall the extension and install it again with this new parameter.
Upvotes: 0