Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 5, 2019 22:12
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/9acd901b2cec4f2f9574e96399e4d205 to your computer and use it in GitHub Desktop.
Save parzibyte/9acd901b2cec4f2f9574e96399e4d205 to your computer and use it in GitHub Desktop.
<?php
/**
* Ejemplo 6 para generar códigos de barras
* con PHP
*
* Generar código y mostrar dependiendo de parámetro GET
*
* @author parzibyte
*/
# Si no hay parámetro, salir
# https://parzibyte.me/blog/2018/08/09/isset-vs-empty-en-php/
if(empty($_GET["texto"])) exit("No proporcionaste el texto en la URL");
# 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 = $_GET["texto"];
$tipo = $generador::TYPE_CODE_128;
$imagen = $generador->getBarcode($texto, $tipo);
header("Content-type: image/png");
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