Tcl Requires Chilkat v11.7.0+
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "payload.text" "https://www.chilkatsoft.com/barcode_overview.asp"
CkJsonObject_UpdateInt $json "render.moduleSize" 8
set fmt [new_CkFormats]
set jsonOut [new_CkJsonObject]
set success [CkFormats_QrCode $fmt "measure" $json $jsonOut]
if {$success == 0} then {
puts [CkFormats_lastErrorText $fmt]
delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
exit
}
puts "fits: [CkJsonObject_BoolOf $jsonOut fits]"
puts "QR version: [CkJsonObject_IntOf $jsonOut {symbols[0].selectedEncoding.version}]"
puts "image would be: [CkJsonObject_IntOf $jsonOut {measurements[0].canvasWidth}] x [CkJsonObject_IntOf $jsonOut {measurements[0].canvasHeight}] pixels"
puts "symbol: [CkJsonObject_IntOf $jsonOut {measurements[0].symbolWidth}] pixels wide at x = [CkJsonObject_IntOf $jsonOut {measurements[0].symbolX}]"
# Would it fit in a space 200 pixels wide?
CkJsonObject_UpdateInt $json "render.maxWidth" 200
set success [CkFormats_QrCode $fmt "measure" $json $jsonOut]
if {$success == 0} then {
puts [CkFormats_lastErrorText $fmt]
delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
exit
}
puts "within 200 pixels, fits: [CkJsonObject_BoolOf $jsonOut fits]"
if {[CkJsonObject_BoolOf $jsonOut "fits"] == 0} then {
puts "reason: [CkJsonObject_stringOf $jsonOut {reasons[0].code}] ([CkJsonObject_stringOf $jsonOut {reasons[0].message}])"
}
# 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)
delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut