Menu

TypeScript Blob URL Generator for Transparent Assets
📰

TypeScript Blob URL Generator for Transparent Assets

DEV Community: typescript·Remove Photo BG Team·8 days ago
#U75S0mIq
#devtotypescript#devto#dev#blob#transparent
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.