survos/barcode-bundle

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

Fund package maintenance!
kbond

Installs: 4 922

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.5.394 2024-11-21 13:58 UTC

This package is auto-updated.

Last update: 2024-11-21 23:47:17 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