What are you trying to achieve?
I was using ImageMagick to resize an image but it does not support HEIC type from iPhones. I heard Sharp is faster but when I implemented in my code, it does not work at all. Am I missing something in my code? The function does not fail but it doesn't resize my image and does not return any error either for HEIC type. My project is Firebase cloud functions with typescript and the image is store in Firebase Storage.
Have you searched for similar questions?
Yes, but found nothing
Are you able to provide a standalone code sample that demonstrates this question?
Code snippet is part of Firebase Storage event: functions.storage.object().onFinalize
I tried to convert straight from the temporary file instead of exporting to another temporary file.
import * as sharp from 'sharp'
await sharp(tempFilePath).resize(300, 300)
In package.json
"dependencies": {
"@google-cloud/storage": "^2.5.0",
"@types/sharp": "^0.22.2",
"child-process-promise": "^2.2.1",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.5",
"firebase-tools": "^4.2.1",
"node-fetch": "^2.2.0",
"secure-compare": "^3.0.1",
"sharp": "^0.22.1",
}
Are you able to provide a sample image that helps explain the question?
Any image I tested did not resize.
Looks like you're creating an image pipeline without using it. sharp does not automatically overwrite the input file, see the api docs here: https://sharp.pixelplumbing.com/en/stable/api-output/
You need to explicitly write the resulting image to a file:
await sharp(tempFilePath).resize(300, 300).toFile(`result.jpg`);
You can also receive it as a buffer:
const resultImage = await sharp(tempFilePath).resize(300, 300).toBuffer();
Please see #1105 for future possible HEIC support in sharp, which will require you to compile libvips and its dependencies from source due to patent liabilities.
What does the image buffer means? I am new to image processing. I know of the video buffer.
@Dara-To Buffer in this context refers to binary data stored in a Node.js Buffer object - see https://nodejs.org/dist/latest/docs/api/buffer.html
I hope this information helped. Please feel free to re-open with more information if further help is required.
Most helpful comment
Looks like you're creating an image pipeline without using it.
sharpdoes not automatically overwrite the input file, see the api docs here: https://sharp.pixelplumbing.com/en/stable/api-output/You need to explicitly write the resulting image to a file:
You can also receive it as a buffer: