load-image
ローカルの画像ファイルをBufferに読み込む
code:mod.ts
import {open, copy, Buffer} from 'deno'
export const loadLocalImage = async (srcPath): Promise<Buffer> => {
const imgFile = await open(srcPath)
// https://github.com/denoland/deno/blob/master/js/buffer.ts
const buf = new Buffer()
await copy(buf, imgFile)
return buf // Buffer {off: 0, buf: []}
}
インターネットから画像データをfetchして、Bufferに読み込む
code:mod.ts
export const fetchImage = async (srcUrl): Promise<Buffer> => {
// https://github.com/denoland/deno/blob/master/js/fetch.ts
const res = await fetch(srcUrl)
return new Buffer(await res.arrayBuffer())
}