Wolfram Research

Function Repository Resource:

ImageToDataURI

Source Notebook

Convert an image into a Data URL, suitable for embedding in web documents

Contributed by: Cody Woodard

ResourceFunction["ImageToDataURI"][image]

convert image into a Data URL, suitable for embedding in web documents.

Examples

Basic Examples

Create a Data URL from an image:

In[1]:=
ResourceFunction["ImageToDataURI"][
 ImageResize[ResourceData["Sample Image: White Dog on a Beach"], 25]]
Out[1]=

Create an image element from Wolfram Language code:

In[2]:=
ExportString[
 XMLElement[
  "img", {"src" -> ResourceFunction["ImageToDataURI"]@
     Rasterize[
      PolyhedronData[Entity["Polyhedron", "RhombicHexecontahedron"], "Graphics3D"], RasterSize -> 50], "alt" -> ""}, {}], "XML"]
Out[2]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information