Skip to main content

Barcode Generator API

REAL DATA

Real, scannable SVG barcodes — EAN-13 with automatic check digits and Code 128 set B. Custom height, optional label, deterministic and safe to hotlink.

Authoritative reference data or standards computation

Base URL
/api/barcodes
Capabilities
1 route
Last updated
July 29, 2026
Data source

GET /api/barcodes/image

Returns the barcode itself (image/svg+xml), not JSON. EAN-13 validates (or computes) the check digit; Code 128 encodes printable ASCII in set B with its check symbol.

Live requestRuns against the public API
No key required
GET/api/barcodes/image?data=5901234123457

Request parameters

Payload to encode. For type=ean13: 13 digits with a valid check digit, or 12 digits to have it computed and appended. For type=code128: 1–40 characters of printable ASCII (space–~).

Symbology: 'ean13' = retail product codes (L/G/R patterns, mod-10 check digit), 'code128' = free-text code set B with mod-103 check symbol.

Bar height in pixels (40–400). The image is 24 px taller when showText=true.

Print the encoded value under the bars in a monospace font. For EAN-13 the label is always the full 13 digits, including a computed check digit.

Response

Example parameters are ready. Send the request to inspect the live response.

Route reference

Code samples Ready-to-copy requests in 4 languages
Choose a code sample language
<img src="https://randomapi.dev/api/barcodes/image?data=5901234123457" alt="Generated image" />
curl -o image.svg "https://randomapi.dev/api/barcodes/image?data=5901234123457"
const res = await fetch("https://randomapi.dev/api/barcodes/image?data=5901234123457");
const svg = await res.text();
import requests

svg = requests.get("https://randomapi.dev/api/barcodes/image?data=5901234123457").text
Parameters Route-specific request inputs 4
data string required

Payload to encode. For type=ean13: 13 digits with a valid check digit, or 12 digits to have it computed and appended. For type=code128: 1–40 characters of printable ASCII (space–~).

allowed: ≤ 40
example: data=5901234123457
type enum

Symbology: 'ean13' = retail product codes (L/G/R patterns, mod-10 check digit), 'code128' = free-text code set B with mod-103 check symbol.

default: ean13
allowed: ean13 | code128
example: type=code128
height int

Bar height in pixels (40–400). The image is 24 px taller when showText=true.

default: 120
allowed: 40 – 400
example: height=200
showText boolean

Print the encoded value under the bars in a monospace font. For EAN-13 the label is always the full 13 digits, including a computed check digit.

default: true
example: showText=false

Documented examples

Build-generated requests and complete responses
3
EAN-13 retail barcode
GET /api/barcodes/image?data=5901234123457
EAN-13 retail barcode
12 digits — the check digit is computed for you
GET /api/barcodes/image?data=590123412345&height=160
12 digits — the check digit is computed for you
Code 128 asset tag, bars only
GET /api/barcodes/image?data=INV-2024-0042&type=code128&showText=false
Code 128 asset tag, bars only

About this API

Coverage & behavior

Returns an actual SVG barcode (Content-Type: image/svg+xml) — a real, scannable encoding, not decorative stripes. Drop it into an <img src>, a label template or a test fixture.

Two symbologies:

  • EAN-13 (default) — the retail barcode. data must be 13 digits with a valid mod-10 check digit, or 12 digits to have the check digit computed and appended for you (it then appears in the label). A wrong 13th digit is a 400 that tells you the expected digit — never a silently broken barcode. Bars use the genuine L/G/R pattern tables with first-digit parity selection: 95 modules — start/center/end guards plus twelve 7-module digit symbols.
  • Code 128, set B (type=code128) — free text: 1–40 characters of printable ASCII (space to ~). Encoded with the Start B code, the mod-103 check symbol and the 13-module stop pattern, exactly as scanners expect.

Rendering: black bars on a white background at 2 px per module with 10-module quiet zones on both sides, so the image width follows the data length. height sets the bar height (40–400 px); showText=true (default) prints the encoded value under the bars in a monospace font and adds 24 px to the image height. The output is fully deterministic — the same URL returns a byte-identical SVG forever and is served with long cache headers, so it is safe to hotlink.

Use it for

  • Product packaging mockups and shelf-label designs that need a scannable EAN-13
  • Fixtures for testing barcode-scanner and POS integrations without a label printer
  • Code 128 asset tags for inventory sheets, badges and internal tools

Frequently asked questions

Are the barcodes actually scannable?

Yes — bar widths follow the real EAN-13 and Code 128 encoding tables and EAN-13 check digits are computed correctly, so a phone scanner reads them.

Can I encode my own value?

Yes — pass data and pick type=ean13 or type=code128; the barcode encodes exactly that value.

What image format is returned?

Crisp SVG that scales without blurring; height and showText control the bar height and the human-readable line.

Standards & references