How to Generate a Barcode Image with Custom Dimensions
Enter non-empty data, choose a supported barcode format, adjust the requested size or text option if needed, and submit it. A successful generation returns base64-encoded PNG image data, while validation or format problems can return an error indication without an image.
What the barcode generator does
A barcode generator turns supplied data into base64-encoded PNG image data when generation succeeds. Use it when you need a barcode image for a product label, inventory record, shipment reference, or another item identifier. The default format is Code 128, and you can also provide a supported format, choose whether text is rendered, and adjust the requested width and height.
The data field is optional, but leaving it empty does not produce an image. The tool instead returns a successful result with an error indication. For a usable barcode, enter the value you want encoded before reviewing the result.
How to generate a barcode
-
Enter the value to encode in the data field. For example, use a product identifier, shipment reference, or other barcode value. Do not leave the field empty if you need an image.
-
Choose a barcode format, or keep the default Code 128. Format names are normalized by lowercasing them, removing hyphens and spaces, and mapping some common underscore forms to compact names. This normalization does not mean that every format is supported, so use a format provided by the tool’s barcode library.
-
Set the requested width and height if needed. Width is converted to an integer and limited to 100 through 2000 for non-empty data. Height is converted to an integer and limited to 40 through 600. If either conversion fails, the corresponding default is used: 400 for width or 100 for height.
-
Decide whether to show the encoded text with the write-text option. Text rendering is enabled by default, but you can disable it when the barcode should be rendered without accompanying text.
-
Submit the settings and inspect the returned result. When generation succeeds, the result contains base64-encoded PNG image data. Save or display that image data using the workflow in which you plan to use the barcode.
-
If you select a numeric format, provide enough numeric content for that format. When the barcode dependency is available and the normalized format is recognized, non-digit characters are removed and the input is limited to the required number of digits; the barcode library supplies a check digit where applicable.
How to read the result
A successful result does not by itself mean that an image was returned. Empty data, insufficient digits for a recognized numeric format, or an unsupported format can produce a successful result with an error indication and no image. If the barcode dependency is unavailable or generation raises an exception, the result can instead be unsuccessful and include an error indication.
When image data is returned, it is PNG data encoded as base64. Treat the width and height settings as normalized requests rather than guaranteed pixel dimensions: the resulting PNG dimensions are not guaranteed to match those settings. If the output is not suitable for a label or layout, adjust the settings and review the new result rather than assuming the requested values describe the final image exactly.
For numeric formats, check that the input has enough digits after non-digit characters are removed. For other formats, verify that the selected format is supported and that the submitted data is non-empty. The tool’s declared network access is false, but that fact does not establish a particular deployment model or make claims about storage, retention, or privacy.
Worked example
A warehouse coordinator needs a barcode image for a product reference and wants the encoded text visible beneath the bars.
Enter the product reference A-4827, keep Code 128 selected, leave text rendering enabled, set a requested width of 800 and height of 160, then submit the settings.
The result should either contain base64-encoded PNG image data after successful generation or contain an error indication without image data if validation or format checks do not pass.
Limitations
- The tool may return an error indication without an image when data is empty, a recognized numeric format lacks enough digits, the selected format is unsupported, the barcode dependency is unavailable, or generation raises an exception.
- Requested width and height do not guarantee the resulting PNG pixel dimensions.
- The declared lack of network access does not establish a deployment model or provide a storage, retention, or privacy guarantee.
Common errors
- If the result has an error indication and no image, check that the data field is not empty and that a numeric format has enough digits after non-digit characters are removed. Correct the input, then submit it again.
FAQ
What barcode format is selected by default?
The default format is Code 128. You can choose another format when it is supported by the barcode library; the tool normalizes the format name before checking it.
What width and height can I request?
For non-empty data, width is limited to 100 through 2000 and height to 40 through 600 after integer conversion. A conversion failure falls back to width 400 or height 100. The resulting PNG dimensions are not guaranteed to match the requested settings.
Why did the result contain an error instead of a barcode image?
An empty value returns a successful result with an error indication and no image. A recognized numeric format can behave the same way when the input has fewer required digits, and an unsupported format can also return an error indication instead of an image.