/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
fixtures/flight/src/GenerateImage.js
19 строк
516 B
Sebastian Markbåge
Allow Passing Blob/File/MediaSource/MediaStream to src of <img>, <video> and <audio> (#32828)
08 апр 2025, 19:11
Не верифицирован
08 апр 2025, 19:11
ea05b75
Код
Авторство
О чём код?
import * as React from 'react'; import {createCanvas} from 'canvas'; export async function GenerateImage({message}) { // Generate an image using an image library const canvas = createCanvas(200, 70); const ctx = canvas.getContext('2d'); ctx.font = '20px Impact'; ctx.rotate(-0.1); ctx.fillText(message, 10, 50); // Rasterize into a Blob with a mime type const type = 'image/png'; const blob = new Blob([canvas.toBuffer(type)], {type}); // Just pass it to React return <img src={blob} />; }