Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Barcode Bundle Laravel Package

mwsimple/barcode-bundle

mwsimple/barcode-bundle integrates barcode generation into Symfony applications, providing services and template helpers for rendering barcode images. It helps add scannable codes to labels, invoices, and other generated documents with minimal setup and configuration.

View on GitHub
Deep Wiki
Context7

Getting Started

Before you install, check the dependency tree. The bundle's last release was August 2016, which puts it in the Symfony 2.8/3.x era. On a modern Laravel app (PHP 8.2+, Symfony 6/7 components via illuminate/*) composer require mwsimple/barcode-bundle will almost certainly fail on constraint resolution. Run this first:

composer show mwsimple/barcode-bundle --all
# inspect "requires" for symfony/framework-bundle, symfony/http-kernel, php

If the constraints are incompatible, the practical path is to use the underlying barcode engine directly (whatever the bundle's composer.json pulls in — commonly a GD-based Code128/EAN renderer) and treat the bundle as documentation of how to wire it up. That is what the "day-to-day" usage really reduces to.

If you are on a compatible Symfony app, the minimal steps are:

// app/AppKernel.php
$bundles = [
    // ...
    new Mwsimple\BarcodeBundle\MwsimpleBarcodeBundle(),
];

Where to look first, in this order:

  1. composer.json — identify the actual barcode library and its PHP/Symfony constraints.
  2. DependencyInjection/Configuration.php — the config tree tells you what's tunable (default format, width/height, colors, renderer).
  3. Resources/config/services.yml (or services.xml) — the service IDs you'll inject.
  4. Any Twig/ extension — if one exists, it shows the intended public API surface.

First use case: generate a Code128 image for an order number and stream it back as a response.

public function barcode(string $code, BarcodeGenerator $gen)
{
    $image = $gen->generate($code, 'C128', ['width' => 300, 'height' => 80]);

    return response($image, 200)
        ->header('Content-Type', 'image/png')
        ->header('Cache-Control', 'public, max-age=86400');
}

Implementation Patterns

Inject the generator service, don't call it statically. The bundle's value is that it configures the engine from a single config block. Keep that: bind the service into your controller/action or a small BarcodeService wrapper so format and sizing live in one place.

class BarcodeService
{
    public function __construct(private BarcodeGenerator $gen) {}

    public function png(string $value, string $type = 'C128'): string
    {
        return $this->gen->generate($value, $type, [
            'width'  => config('barcode.width', 300),
            'height' => config('barcode.height', 80),
            'format' => 'png',
        ]);
    }
}

Render-once, store-forever. Barcode output is deterministic for a given (value, format, size). The right production pattern is generate → write to disk/S3 → serve the URL. This removes the generator from the hot path, makes the barcode cacheable by CDN, and sidesteps output-buffering bugs.

$path = "barcodes/{$order->number}.png";
Storage::disk('public')->put($path, $barcodeService->png($order->number));

Embedding in PDFs. Generate the PNG to a temp path, then hand the path (not raw bytes) to dompdf/Snappy. Passing binary strings into HTML works but bloats the document; base64 data-URIs are the middle ground.

Batch jobs. For label runs (hundreds/thousands of SKUs), wrap generation in a queued job and chunk it. Keep an eye on memory — image libraries are GD/Imagick-backed and are not always freed promptly.

Testing. Don't snapshot image bytes. Assert on the HTTP contract instead: status 200, Content-Type: image/png, non-empty body, and that the magic bytes are \x89PNG. Validate input separately — EAN-13 checksums, Code128 character-set legality — before you ever call the generator, so bad data fails loudly rather than producing a garbage image.

Twig/Blade. If the bundle ships a Twig function, it will be a thin wrapper over the service. In Laravel, register an equivalent Blade directive or just inject BarcodeService into the view — the abstraction is trivial, so don't chase bundle-specific Twig glue on Laravel.

Gotchas and Tips

It is effectively abandoned. Zero stars, zero dependents, last release 2016. Treat it as reference implementation, not a dependency. Fork it, or lift the ~50 lines of service wiring into your own package, and you own the maintenance instead of inheriting a dead constraint graph.

GD/Imagick availability. These bundles almost always assume ext-gd. Check php -m in every environment (local, CI, container) — a missing GD extension surfaces as a fatal error deep in the renderer, not a helpful exception. Prefer Imagick if you need anti-aliasing on large prints.

Binary responses and output buffering. If you echo image bytes anywhere above the framework's response layer (a stray dump(), a BOM in an included file, a debug toolbar middleware), the PNG is corrupted with no visible error — the browser just shows a broken image. Always return through the response object.

Format-specific input rules are the most common bug source. EAN-13 needs exactly 12 digits plus a valid checksum; UPC-A is 11+1; Code128 has character-set constraints and needs CODE128B/CODE128C selection for dense numeric data. Validate at the boundary and reject with a 422 rather than letting the library render an unreadable symbol.

Config quirks. In these older bundles, config rarely flows anywhere you expect — options are often baked into the service definition at container-compile time and silently ignore per-call overrides. Verify by generating with two different width values and comparing byte length. If overrides are ignored, pass options at the engine level instead of via bundle config.

Extension point: the renderer, not the generator. The most useful seam is the class that turns the barcode matrix into an image. Swap that one class (PNG → SVG → PDF) and you keep all format/validation logic intact. SVG output matters if you're printing labels at variable DPI.

Don't echo user input into barcode content unvalidated. If the value is written into a filename derived from the payload, normalize and whitelist it — barcodes/{$order->number}.png is safe only because number is generated, not user-supplied.

Migration path if you're starting fresh in Laravel: picqer/php-barcode-generator (1D, lean, actively maintained), endroid/qr-code (2D), or milon/barcode (Laravel-native wrapper over TCPDF). All of these cover the same ground with PHP 8 support and give you a service you can bind in a ServiceProvider in five lines — which is exactly what this bundle was, minus the decade of rot.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons