Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.7.0+

Embed a QR Code in HTML as a Data URI

See more QR Code Examples

Demonstrates putting a QR code directly into an HTML page or HTML email with no separate image file. The base64 PNG returned by QrCode becomes the src of an img tag as a data URI, which is the MIME type from outputs[0].mimeType followed by the base64 from outputs[0].base64.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  This example requires the Chilkat API to have been previously unlocked.
;  See Global Unlock Sample for sample code.

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("payload.text","https://www.chilkatsoft.com/")
$oJson.UpdateInt("render.moduleSize",5)

$oFmt = ObjCreate("Chilkat.Formats")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oFmt.QrCode("generate",$oJson,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oFmt.LastErrorText & @CRLF)
    Exit
EndIf

;  A data URI has the form  data:<MIME type>;base64,<base64 data>
$oSbHtml = ObjCreate("Chilkat.StringBuilder")
$oSbHtml.Append("<html><body><p>Scan to visit chilkatsoft.com</p><img alt=""QR code"" width=""")
$oSbHtml.AppendInt($oJsonOut.IntOf("outputs[0].width"))
$oSbHtml.Append(""" height=""")
$oSbHtml.AppendInt($oJsonOut.IntOf("outputs[0].height"))
$oSbHtml.Append(""" src=""data:")
$oSbHtml.Append($oJsonOut.StringOf("outputs[0].mimeType"))
$oSbHtml.Append(";base64,")
$oSbHtml.Append($oJsonOut.StringOf("outputs[0].base64"))
$oSbHtml.Append("""></body></html>")

$bSuccess = $oSbHtml.WriteFile("qa_output/qr_page.html","utf-8",False)
If ($bSuccess = False) Then
    ConsoleWrite($oSbHtml.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("image: " & $oJsonOut.IntOf("outputs[0].width") & " x " & $oJsonOut.IntOf("outputs[0].height") & " pixels" & @CRLF)
ConsoleWrite("HTML length: " & $oSbHtml.Length & @CRLF)

;  The page, as a browser shows it:

;  image

;  Sample output:

;  image: 185 x 185 pixels
;  HTML length: 1211