survos/barcode-bundle

Integrates picqer/php-barcode-generator in a Symfony application

Fund package maintenance!
kbond

Installs: 4 832

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.5.378 2024-07-08 19:24 UTC

This package is auto-updated.

Last update: 2024-11-04 17:03:13 UTC


README

Symfony Bundle for the picqer/php-barcode-generator library, to generate an SVG barcode within twig.

composer req survos/barcode-bundle
{# as a filter #}
{{ '12345'|barcode }}

{# as a function #}
{{ barcode(random(), 2, 80, 'red' }}

To set default values (@todo: install recipe)

# config/packages/barcode.yaml
barcode:
  widthFactor: 3
  height: 120
  foregroundColor: 'purple'

Proof that it works

Requirements:

  • Locally installed PHP 8, with GD or Imagick
  • Symfony CLI
  • sed (to change /app to / without opening an editor)
symfony new BarcodeDemo --webapp && cd BarcodeDemo
symfony composer req survos/barcode-bundle
symfony console make:controller AppController
sed -i "s|/app|/|" src/Controller/AppController.php 

cat <<'EOF' > templates/app/index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
{{ 'test'|barcode }} or {{ barcode('test', 2, 80, 'red') }}
{% endblock %}
EOF

#echo "{{ 'test'|barcode }} or {{ barcode('test', 2, 80, 'red') }} " >> templates/app/index.html.twig
symfony server:start -d
symfony open:local