AutoIt Requires Chilkat v11.7.0+
AutoIt
Measure a QR Code without Rendering It
See more QR Code Examples
Demonstrates the measure operation, which does everything generate does except draw the image. It reports the version chosen and the exact size the image would have, which is useful for laying out a page or a label before any image is made. Unlike generate, a code that does not fit the limits is not a failure for measure: the call succeeds, fits is false, and reasons[] says why.Chilkat AutoIt Downloads
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/barcode_overview.asp")
$oJson.UpdateInt("render.moduleSize",8)
$oFmt = ObjCreate("Chilkat.Formats")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oFmt.QrCode("measure",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oFmt.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("fits: " & $oJsonOut.BoolOf("fits") & @CRLF)
ConsoleWrite("QR version: " & $oJsonOut.IntOf("symbols[0].selectedEncoding.version") & @CRLF)
ConsoleWrite("image would be: " & $oJsonOut.IntOf("measurements[0].canvasWidth") & " x " & $oJsonOut.IntOf("measurements[0].canvasHeight") & " pixels" & @CRLF)
ConsoleWrite("symbol: " & $oJsonOut.IntOf("measurements[0].symbolWidth") & " pixels wide at x = " & $oJsonOut.IntOf("measurements[0].symbolX") & @CRLF)
; Would it fit in a space 200 pixels wide?
$oJson.UpdateInt("render.maxWidth",200)
$bSuccess = $oFmt.QrCode("measure",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oFmt.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("within 200 pixels, fits: " & $oJsonOut.BoolOf("fits") & @CRLF)
If ($oJsonOut.BoolOf("fits") = False) Then
ConsoleWrite("reason: " & $oJsonOut.StringOf("reasons[0].code") & " (" & $oJsonOut.StringOf("reasons[0].message") & ")" & @CRLF)
EndIf
; What measure reported, drawn as a diagram. The measure operation itself makes no image:
;
; Sample output:
; fits: True
; QR version: 4
; image would be: 328 x 328 pixels
; symbol: 264 pixels wide at x = 32
; within 200 pixels, fits: False
; reason: noFit (exceedsMaxWidth)