You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Library looks super cool, I am just pretty bad with photo handling and was hoping someone could provide a react native example with minimal dependencies
I'm looking for the same. I'm uploading images from a react-native mobile app and it would be great to generate a hash to go along with the upload. It seems like we need to do the following steps:
resize the image to fit within 100x100
Convert the image into a pixel array where each item is the rgba value of the pixel (I don't know how to do this yet)
Pass the pixel array to rgbaToThumbHash - but I'm confused about the return value of this function - it's not a string/hash?
Pass the pixel array to rgbaToThumbHash - but I'm confused about the return value of this function - it's not a string/hash?
It's a buffer of bytes (specifically a Uint8Array). You can get a string from a buffer by converting the buffer to base64, and you can get a buffer from a string by converting the string from base64. This is already in the JavaScript example code:
constbinaryThumbHash=ThumbHash.rgbaToThumbHash(pixels.width,pixels.height,pixels.data)// ThumbHash to data URLconstplaceholderURL=ThumbHash.thumbHashToDataURL(binaryThumbHash)// If you want to use base64 instead of binary...constbinaryToBase64=binary=>btoa(String.fromCharCode(...binary))constbase64ToBinary=base64=>newUint8Array(atob(base64).split('').map(x=>x.charCodeAt(0)))constthumbHashToBase64=binaryToBase64(binaryThumbHash)constthumbHashFromBase64=base64ToBinary(thumbHashToBase64)
@evanwbtoa does not exist in a react native context, I think that's where the issue is. I am not too familiar with image encoding and decoding, so I think an example that works in that environment would be super helpful. Additionally, getting the raw pixel data pixels.data is not as easy without canvas in react native.
Edit: Updating to add that I commented on an expo dev's release post for support for this library with expo-image and they're going to be releasing a native implementation built in soon.
Hi!
I've added a @luckypear/react-native-thumbhash library for react native. you can check here
you can use this library just like react-native-blurhash, which i referenced a lot!
It's a beta release a.t.m, but i am working on it and any contributions are welcome.
Activity
jamiechong commentedon Jan 10, 2024
I'm looking for the same. I'm uploading images from a react-native mobile app and it would be great to generate a hash to go along with the upload. It seems like we need to do the following steps:
rgbavalue of the pixel (I don't know how to do this yet)rgbaToThumbHash- but I'm confused about the return value of this function - it's not a string/hash?I'm looking to use the hash with expo-image
I might also be unblocked if there was a
base64ToThumbHashfunctionevanw commentedon Jan 10, 2024
Sorry, I don't know anything about React Native.
It's a buffer of bytes (specifically a
Uint8Array). You can get a string from a buffer by converting the buffer to base64, and you can get a buffer from a string by converting the string from base64. This is already in the JavaScript example code:Joshandrews43 commentedon Jan 11, 2024
@evanw
btoadoes not exist in a react native context, I think that's where the issue is. I am not too familiar with image encoding and decoding, so I think an example that works in that environment would be super helpful. Additionally, getting the raw pixel datapixels.datais not as easy without canvas in react native.Edit: Updating to add that I commented on an expo dev's release post for support for this library with
expo-imageand they're going to be releasing a native implementation built in soon.jamiechong commentedon Jan 11, 2024
@Joshandrews43 can you share a link to that post?
yjb94 commentedon Jul 22, 2024
Hi!
I've added a
@luckypear/react-native-thumbhashlibrary for react native. you can check hereyou can use this library just like react-native-blurhash, which i referenced a lot!
It's a beta release a.t.m, but i am working on it and any contributions are welcome.