So I want to use the sharp
package in combination with canvas
to process and draw some images in Nodejs. When I try to load an image using sharp like this:
const buffer = await sharp("E:/PathToProject/image_150x150.png").toFormat('png').toBuffer()
then the programm just crashes without any output. So wrapping it in a try-catch block doesn't output anything. Also, using .then().catch() instead of async/await doesn't help as well. What i've tried so far:
const buffer = await sharp("E:/PathToProject/image_150x150.png")
.png()
.toBuffer()
const buffer = await sharp("E:/PathToProject/image_150x150.png")
.toFormat('png')
.toBuffer()
const { data, info } = await sharp("E:/PathToProject/image_150x150.png")
.toFormat('png')
.toBuffer({ resolveWithObject: true })
sharp("E:/PathToProject/image_150x150.png")
.toFormat('png')
.toBuffer()
.then(buffer => {
console.log("This is never printed")
})
.catch(err => {
console.error("This is also never printed")
})
The above examples are from the docs.
By doing each step of the chain in a separate line, I figured out that toBuffer()
crashes the program. Does somebody have a clue what is going wrong here?