On this page:
load-image-bitmap
current-svg-base-dir

11 Images🔗ℹ

<image> support loads a local file or a base64 data: URI into a bitmap%, then fits it into its declared viewport the same way a nested viewBox does (reusing compute-viewbox-matrix). Remote http(s):// (or any other URI scheme) references are deliberately never fetched — a privacy/SSRF policy decision, not a missing feature — and a plain, non-base64-encoded data: URI (e.g. data:image/svg+xml,<svg>...</svg>) isn’t decoded either (a disclosed, narrower gap). Loading an SVG file itself as an <image> source (rather than a raster PNG/JPEG) is also not supported.

procedure

(load-image-bitmap href)  (or/c (is-a?/c bitmap%) #f)

  href : string?
Loads the bitmap an <image>’s href (or xlink:href) refers to, or returns #f if it can’t be loaded for any reason — a data: URI recognized but not base64-encoded, a remote (scheme://) reference, a relative local path that doesn’t resolve against current-svg-base-dir, a missing file, or image bytes the underlying codec can’t decode (bitmap%’s own read-bitmap doesn’t raise on garbage image data; it silently returns a broken 1×1 bitmap, which this function detects via ok? and treats the same as any other failure). Never raises.

A data:image/...;base64,... URI is decoded directly. Anything matching scheme:// for any scheme is treated as a remote reference and always returns #f deliberately, this library never fetches network resources. Anything else is treated as a local file path: percent-decoded, and resolved against current-svg-base-dir if it’s relative and that parameter is set.

(load-image-bitmap "data:image/png;base64,iVBORw0KGgo...")
(load-image-bitmap "icon.png")                    ; relative to current-svg-base-dir, if set
(load-image-bitmap "https://example.com/x.png")   ; #f -- never fetched

A bitmap loaded via load-image-bitmap and drawn onto a fresh dc:

a small gold circle bitmap, framed with a thin black border

parameter

(current-svg-base-dir)  (or/c path? #f)

(current-svg-base-dir base-dir)  void?
  base-dir : (or/c path? #f)
A parameter holding the directory relative <image> hrefs resolve against. svg-file->bitmap, svg-file->pict, and svg-doc->pict (when given its own base-dir argument) all set this to the SVG file’s own directory around rendering; svg-string->bitmap/svg-string->pict don’t set it at all (there’s no file, and thus no directory, to resolve against), so a relative <image> reference inside a string-sourced document simply won’t resolve — an absolute path still works either way, regardless of how the document was loaded.

(parameterize ([current-svg-base-dir (string->path "/home/user/icons/")])
  (load-image-bitmap "logo.png"))  ; resolves to /home/user/icons/logo.png