---
title: Generate Barcode as SVG/PNG API
slug: generate-barcode-svg-png
url: https://apyhub.com/frolic/service/generate-barcode-svg-png
provider: Hakimi Labs
categories: [Output Kit]
tags: [barcode-generation, barcode, qr-alternatives, labeling, asset-tracking]
auth: api_key
version: 1.0
service_type: sync
endpoints: 1
atoms: 5
mcp: true
---

# Generate Barcode as SVG/PNG API

Generate PNG or SVG barcodes from a string. Supports code128, code39, EAN, UPC, datamatrix, and pdf417 with custom colours and sizing.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/frolic/generate-barcode-svg-png` | What it does Generates a barcode from the supplied body fields and returns the rendered barcode as… | 5 |

## Endpoint reference

### Generate Barcode

`POST https://api.eu.apyhub.com/frolic/generate-barcode-svg-png` · 5 atoms · accepts `application/x-www-form-urlencoded` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `bg` | body | string | no | Background colour, hex such as FFFFFF Default: `FFFFFF`. |
| `fg` | body | string | no | Foreground colour, hex such as 000000 Default: `000000`. |
| `data` | body | string | yes | Content to encode; ean13, ean8 and upca need digits with a valid check digit Example: `FROLIC-12345`. |
| `type` | body | string | no | code128 (default), code39, ean13, ean8, upca, datamatrix or pdf417 One of: code128, code39, ean13, ean8, upca, datamatrix, pdf417. Default: `code128`. |
| `width` | body | integer (int32) | no | Width in pixels (32-2000; default 400, or 300 for datamatrix) |
| `format` | body | string | no | png or svg One of: png, svg. Default: `png`. |
| `height` | body | integer (int32) | no | Height in pixels (32-2000; default 150, or 300 for datamatrix) |
| `margin` | body | integer (int32) | no | Quiet zone around the code (0-50) Default: `10`. |

#### Quickstart

Generate a barcode from the required `data` value and receive the image bytes in response.

```bash
curl -X POST "https://api.eu.apyhub.com/frolic/generate-barcode-svg-png" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "data=FROLIC-12345"
```

#### What you'll get back

Returns a binary file stream (`string` with `format: "binary"`), not a JSON object.

```text
<binary barcode image>
```

## About

## What it does
Barcode Generator turns a string into a downloadable barcode image. Send `data`, choose a barcode `type`, and optionally set `format`, `width`, `height`, `margin`, `bg`, and `fg` to control the output.

It supports `code128`, `code39`, `ean13`, `ean8`, `upca`, `datamatrix`, and `pdf417`. For `ean13`, `ean8`, and `upca`, the input data must be digits with a valid check digit. The response is binary image data, returned as either `png` or `svg`.

Use it when you need barcodes for product labels, order slips, shipping workflows, inventory systems, or generated documents. You can keep the default dimensions for standard labels or adjust the size and quiet zone to fit your print layout.

Barcode Generator is a simple way to generate machine-readable codes from application data without building barcode rendering into your own stack.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/frolic/service/generate-barcode-svg-png
