Skip to contents

Reads an image from a file path or URL, optionally resizes it, and returns a base64-encoded PNG string suitable for AI vision APIs.

Usage

b64EncodeImage(img_path, max_width = 1000)

Arguments

img_path

Character. File path or URL to the image.

max_width

Numeric. Maximum width in pixels. Images wider than this are scaled down proportionally. Default 1000.

Value

Character. Base64-encoded PNG string.

Details

**Processing:** - Validates file existence or URL reachability - Reads image using magick - Resizes if width exceeds max_width - Converts to PNG format - Returns base64-encoded string

**Supported formats:** Any format readable by magick (PNG, JPEG, GIF, WebP, etc.)

See also

Other image-utils: image-utils

Examples

if (FALSE) { # \dontrun{
# Encode local file
b64 <- b64EncodeImage("artwork.png")

# Encode with custom max width
b64 <- b64EncodeImage("large-image.jpg", max_width = 2000)

# Encode from URL
b64 <- b64EncodeImage("https://example.com/image.png")
} # }