Skip to content

How to handle premultiplied images in JS #44

Open

Description

@skycoop

I'm using sharp to resize the images for use with thumbhash with user uploaded images like so

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions