Bluesky app fork with some witchin' additions 馃挮
at main 21 lines 602 B view raw
1import React from 'react' 2 3function detectMime(buf: Buffer): string { 4 if (buf[0] === 0xff && buf[1] === 0xd8) return 'image/jpeg' 5 if (buf[0] === 0x89 && buf[1] === 0x50) return 'image/png' 6 if (buf[0] === 0x52 && buf[1] === 0x49) return 'image/webp' 7 if (buf[0] === 0x47 && buf[1] === 0x49) return 'image/gif' 8 return 'image/jpeg' 9} 10 11export function Img( 12 props: Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src'> & {src: Buffer}, 13) { 14 const {src, ...others} = props 15 return ( 16 <img 17 {...others} 18 src={`data:${detectMime(src)};base64,${src.toString('base64')}`} 19 /> 20 ) 21}