Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 5, 2019 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/5bba052777fe683c11fb1f02c4a36836 to your computer and use it in GitHub Desktop.
Save parzibyte/5bba052777fe683c11fb1f02c4a36836 to your computer and use it in GitHub Desktop.
<?php
/**
* Ejemplo 5 para generar códigos de barras
* con PHP
*
* Forzar descarga de imagen con código de barras
*
* @author parzibyte
*/
# Incluimos el autoload
require_once "vendor/autoload.php";
# Indicamos que usaremos el namespace de BarcodeGeneratorPNG
use Picqer\Barcode\BarcodeGeneratorPNG;
# Crear generador
$generador = new BarcodeGeneratorPNG();
# Ajustes
$texto = "parzibyte.me";
$tipo = $generador::TYPE_CODE_128;
$imagen = $generador->getBarcode($texto, $tipo);
# Sugerir nombre para guardar
$nombreArchivo = "codigo_de_barras.png";
# Imprimir encabezados
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=$nombreArchivo");
echo $imagen;
# No imprimas nada después de esto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment