vcapi-workers / Exports / utils/image
Module: utils/image
画像を扱うユーティリティ。おもに image downloader 向けレスポンスを想定 この関数たちを使うと JSON を PNG画像に埋め込んで返せる
Table of contents
Variables
Functions
Variables
contentTypePng
• Const contentTypePng: Object
Type declaration
| Name | Type |
|---|---|
Content-Type | "image/png" |
Defined in
src/utils/image.ts:15 (opens in a new tab)
emptyPng
• Const emptyPng: Uint8Array
4x4 sRGB 白単色 PNG
Defined in
src/utils/image.ts:12 (opens in a new tab)
Functions
bytes2Image
▸ bytes2Image(buffer): ImageData
バイト列を ImageData にします
Remarks
先頭に長さを 32bit int で格納したのちバイト列をそのまま詰めた画像になります
See
Parameters
| Name | Type |
|---|---|
buffer | Uint8Array |
Returns
ImageData
そのまま png 関数で使う、{ width, height, data }
Defined in
src/utils/image.ts:49 (opens in a new tab)
emptyImage
▸ emptyImage(c): Response
image downloader 向けの c.text('')
Parameters
| Name | Type |
|---|---|
c | Context<any, any, {}> |
Returns
Response
Defined in
src/utils/image.ts:18 (opens in a new tab)
json2Image
▸ json2Image(json): ImageData
json オブジェクトを ImageData にします
Remarks
先頭に長さを 32bit int で格納したのちバイト列をそのまま詰めた画像になります
See
Parameters
| Name | Type |
|---|---|
json | object |
Returns
ImageData
そのまま png 関数で使う、{ width, height, data }
Defined in
src/utils/image.ts:39 (opens in a new tab)
png
▸ png(c, png): Response
PNG画像のレスポンスを返す
Remarks
普通は json2Image や bytes2Image で生成した引数を渡して使うはず
width, height は 256 以下推奨
Parameters
| Name | Type | Description |
|---|---|---|
c | Context<any, any, {}> | - |
png | ImageData | ImageData は { width, height, data } |
Returns
Response