Convert Cloudinary image url to base64
Suppose I have an image at a public URL like this
Does Cloudinary provide any utility to convert it to base64 data?
I can't find anything related to this on either the knowledge base or forum, so I thought I'd ask just in case.
Here is my use case if that helps: I want to place a LQIP while waiting for the real image to finish loading:
.resp-image-placeholder {
background-image: url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHBwgHBg0ICBMLDRIXERIQDhIJDRENDg0YFxYZGCITFhUaHysjGh0oKRUWJDUlKC0vMjIyGSI4PTcwPCsxMi8BCgsLDg0OHBAQHC8lFigvLy8vLy8vLy8vLy8vLy8vNS8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vL//AABEIABAAGAMBIgACEQEDEQH/xAAZAAABBQAAAAAAAAAAAAAAAAAEAAEDBQf/xAAbEAACAwADAAAAAAAAAAAAAAAAAwECEQQSIf/EABYBAQEBAAAAAAAAAAAAAAAAAAMCAf/EABcRAQEBAQAAAAAAAAAAAAAAAAERAAL/2gAMAwEAAhEDEQA/ANhfeF00HTyYtOEfMb3rkAiNrbTCakTWL7RgwG9/gg2XJzZv/9k=");
}
-
Hi Trang,
Yes, the Cloudinary SDK includes utilities to decode and encode Base64.
Here is an example class in Java SDK.
Regards,
Francis1 -
Hi Trang,
You can use the code of base64Encode from Node.js SDK or check out details from:
https://www.tutorialspoint.com/converting-images-to-a-base64-data-url-using-javascript
Regards,
Mo
0 -
Hi Mo,
Thanks for the link. That seems like a good approach.
0 -
Hi Trang,
Glad to hear.
Regards,
Mo
0
Post is closed for comments.
Comments
5 comments