Understand barcode scaling and dimensions
masterDimensions and DPI
bwip-js targets a display resolution of 72dpi. It maps 1pt to 1px. If you need to convert width or height (which are in millimeters) to pixels, use the factor 2.835 px/mm.
Module Width and Scaling
Barcodes are composed of "modules" (the narrowest bar in linear barcodes, or the grid unit in 2D barcodes). To ensure barcodes remain "in spec," bwip-js uses a constant module size and grows images in "quantums."
- The
scaleparameter effectively requests a specific module width:scale=1maps to a 1px module,scale=2to a 2px module, etc. - When you specify
widthorheight,bwip-jscalculates the requested dimension multiplied by the scale, then divides by the number of modules. It uses the floor of that value as the module width. This ensures the barcode is as large as possible without exceeding the requested dimensions or violating module size specifications.