How to handle premultiplied images in JS
- Dominant language
- Swift
- Stars
- 4.2k
- Forks
- 91
- PR merge metrics
- No merged PRs in 30d
Description
I'm using `sharp` to resize the images for use with `thumbhash` with user uploaded images like so
```ts
const { data, info } = await sharp(image)
.resize({ width: 100, height: 100, fit: "inside" })
.ensureAlpha()
.raw()
.toBuffer({ resolveWithObject: true });
console.log(info)
/*
{
format: 'raw',
width: 100,
height: 100,
channels: 4,
depth: 'uchar',
premultiplied: true,
size: 40000
}
*/
const thumbhash = rgbaToThumbHash(info.width, info.height, data);
```
I noticed that `sharp` is outputting premultiplied images depending on the import format (PNG always seems to be premultiplied, webp isn't, etc.). I can't figure out a way to disable premultiplication or unpremultiply using sharp, so I was wondering if there was a way to handle premultiplied images within `rgbaToThumbHash` or process it myself before passing it to `rgbaToThumbHash`?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.