Sharp: Is there a way to get an "Uint8ClampedArray" and create a sharp from it?

Created on 12 Sep 2019  路  2Comments  路  Source: lovell/sharp

What are you trying to achieve?

I'm trying to do some transformations to get a Uint8ClampedArray since I need it to run blurhash on it, a blur library you can find here, but to get the Uint8ClampedArray I need to run some transformation from the UInt8Array that I get from running .raw() function.

Is there a way where I can get a Uint8ClampedArray from the sharp library, and set a sharp from a Uint8ClampedArray? Since I need to run this backward to get a base64 image at the very end?

Have you searched for similar questions?

Yes, no luck so far, I was wondering maybe the creator or mantainers of the library can have a clue on this.

Are you able to provide a standalone code sample that demonstrates this question?

const { data, info } = await sharp('input.jpg')
  .raw()
  .toBuffer({ resolveWithObject: true });
data.toClampedArray() // This is the method or hack I'm looking for

Are you able to provide a sample image that helps explain the question?

No.

question

All 2 comments

The Node.js Buffer type is already 8-bit unsigned so using something like Uint8ClampedArray.from(data) should "just work".

Hope this helped, please reopen with more details if not.

Was this page helpful?
0 / 5 - 0 ratings