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

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

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

set json = Server.CreateObject("Chilkat.JsonObject")
success = json.UpdateString("payload.text","https://www.chilkatsoft.com/barcode_overview.asp")
success = json.UpdateInt("render.moduleSize",8)

set fmt = Server.CreateObject("Chilkat.Formats")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")
success = fmt.QrCode("measure",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( fmt.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "fits: " & jsonOut.BoolOf("fits")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "QR version: " & jsonOut.IntOf("symbols[0].selectedEncoding.version")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "image would be: " & jsonOut.IntOf("measurements[0].canvasWidth") & " x " & jsonOut.IntOf("measurements[0].canvasHeight") _
     & " pixels") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "symbol: " & jsonOut.IntOf("measurements[0].symbolWidth") & " pixels wide at x = " & jsonOut.IntOf("measurements[0].symbolX")) & "</pre>"

'  Would it fit in a space 200 pixels wide?
success = json.UpdateInt("render.maxWidth",200)
success = fmt.QrCode("measure",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( fmt.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "within 200 pixels, fits: " & jsonOut.BoolOf("fits")) & "</pre>"
If (jsonOut.BoolOf("fits") = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( "reason: " & jsonOut.StringOf("reasons[0].code") & " (" & jsonOut.StringOf("reasons[0].message") & ")") & "</pre>"
End If

'  What measure reported, drawn as a diagram.  The measure operation itself makes no image:

'  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)

%>
</body>
</html>