AutoIt Requires Chilkat v11.7.0+
AutoIt
QR Code with a Physical Size in Millimeters at a Printer DPI
See more QR Code Examples
Demonstrates sizing a QR code for print. With render.units set to mm (or in, or pt) the module size is a physical length, and render.dpi says how many pixels the printer or the image has per inch. A module is always a whole number of pixels, because modules of uneven width scan badly, so the size asked for is rounded to the nearest pixel and the response reports the size actually used. The PNG records the dpi, so software that honors it prints the image at that physical size.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/")
; Modules of 0.5 mm, for a 300 dpi printer.
$oJson.UpdateString("render.units","mm")
$oJson.UpdateNumber("render.moduleSize","0.5")
$oJson.UpdateInt("render.dpi",300)
$oJson.UpdateString("output.path","qa_output/qr_300dpi.png")
$oJson.UpdateBool("output.overwrite",True)
$oJson.UpdateString("output.return","none")
$oFmt = ObjCreate("Chilkat.Formats")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oFmt.QrCode("generate",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oFmt.LastErrorText & @CRLF)
Exit
EndIf
; 0.5 mm at 300 dpi is 5.9 pixels, so each module is drawn 6 pixels wide.
ConsoleWrite("requested module: " & $oJsonOut.StringOf("measurements[0].requestedPitch") & " pixels" & @CRLF)
ConsoleWrite("module drawn: " & $oJsonOut.IntOf("measurements[0].pitch") & " pixels = " & $oJsonOut.StringOf("measurements[0].moduleSize") & " mm" & @CRLF)
ConsoleWrite("size was rounded: " & $oJsonOut.BoolOf("measurements[0].pitchAdjusted") & @CRLF)
ConsoleWrite("image: " & $oJsonOut.IntOf("measurements[0].canvasWidth") & " x " & $oJsonOut.IntOf("measurements[0].canvasHeight") & " pixels" & @CRLF)
ConsoleWrite("printed size: " & $oJsonOut.StringOf("measurements[0].physicalWidth") & " x " & $oJsonOut.StringOf("measurements[0].physicalHeight") & " mm" & @CRLF)
; The image. A web page shows it pixel for pixel. Printed at 300 dpi it is 18.8 mm wide:
;
; When the exact size matters more than getting an image, requireExactPitch makes a size
; that is not a whole number of pixels a failure (noFit) instead of rounding it.
$oJson.UpdateBool("render.requireExactPitch",True)
$bSuccess = $oFmt.QrCode("generate",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite("requireExactPitch: " & $oJsonOut.StringOf("errors[0].code") & " (" & $oJsonOut.StringOf("errors[0].message") & ")" & @CRLF)
EndIf
; Sample output:
; requested module: 5.905512 pixels
; module drawn: 6 pixels = 0.508 mm
; size was rounded: True
; image: 222 x 222 pixels
; printed size: 18.796 x 18.796 mm
; requireExactPitch: noFit (the symbol does not fit the render constraints: pitchAdjusted)