UNPKG

@vladmandic/face-api

Version:

FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS

13 lines (10 loc) 451 B
import { bufferToImage } from './bufferToImage'; import { fetchOrThrow } from './fetchOrThrow'; export async function fetchImage(uri: string): Promise<HTMLImageElement> { const res = await fetchOrThrow(uri); const blob = await (res).blob(); if (!blob.type.startsWith('image/')) { throw new Error(`fetchImage - expected blob type to be of type image/*, instead have: ${blob.type}, for url: ${res.url}`); } return bufferToImage(blob); }