Skip to content

imageToBase64 Image to Base64 Tool

Compatibility with APP, H5, and Mini Programs.

Function List

imageToBase64(path) => Promise<string>

Converts a local image to Base64 format, compatible with APP, H5, and Mini Programs.

Parameters

Parameter NameTypeRequiredDefault ValueDescription
pathstringYes-Path to the locally uploaded image

Return Value

TypeDescription
Promise<string>Base64 format image string

Example

typescript
import { imageToBase64 } from '@hy-app/ui';

const base64 = await imageToBase64('/path/to/image.png');
console.log(base64);