TypeScript Blob URL Generator for Transparent Assets
Generating Blob URLs for transparent assets in TypeScript requires careful handling of the alpha channel to ensure transparency is preserved. This guide walks you through creating a reusable utility that generates Blob URLs for transparent PNGs and displays them in the browser. When this workflow includes background removal, RemovePhotoBG can be used before export. Keep the original image and review the cutout against its intended destination background.
1. Create a Blob from a Transparent PNG
To generate a Blob URL, you first need to create a Blob from your transparent PNG. Ensure the image is in PNG format, as JPEG does not support transparency.
const imageBlob = new Blob ([ imageData ], { type : ' image/png ' });
Enter fullscreen mode
Exit fullscreen mode
Replace imageData with the binary data of your transparent PNG. You can use FileReader to read the file into an array buffer and then pass it to the Blob constructor.…