Skip to content

Instantly share code, notes, and snippets.

@dcoppari
Created June 8, 2024 14:20
Show Gist options
  • Save dcoppari/124f1d99025ae2613c8c72fd79d34f5b to your computer and use it in GitHub Desktop.
Save dcoppari/124f1d99025ae2613c8c72fd79d34f5b to your computer and use it in GitHub Desktop.
MagicQR - A tool for generate PCL qr codes
#!/bin/bash
# Verificar la cantidad de parámetros
if [ "$#" -ne 2 ]; then
echo "Uso: $0 <texto_del_qr> <archivo_destino>"
exit 1
fi
# Variables
URL="$1"
TMP_FILE="$(mktemp)"
QR_IMAGE="$TMP_FILE.png"
PCL_FILE="$TMP_FILE.tmp.pcl"
FIXED_PCL_FILE="$2"
# Generar el código QR
qrencode -m0 -s2 -lL -o "$QR_IMAGE" "$URL"
if [ $? -ne 0 ]; then
echo "Error: Falló la generación del código QR." >&2
exit 1
fi
# Convertir la imagen a PCL
convert -monochrome "$QR_IMAGE" "$PCL_FILE"
if [ $? -ne 0 ]; then
echo "Error: Falló la conversión de la imagen a PCL." >&2
exit 1
fi
# Verificar si el archivo PCL se generó correctamente y no está vacío
if [ ! -s "$PCL_FILE" ]; then
echo "Error: El archivo PCL está vacío o no existe." >&2
exit 1
fi
# Eliminar los primeros 8 bytes del archivo PCL
dd if="$PCL_FILE" of="$FIXED_PCL_FILE" bs=1 skip=7 status=none
if [ $? -ne 0 ]; then
echo "Error: Falló el ajuste del archivo PCL (eliminación de primeros 8 bytes)." >&2
exit 1
fi
# Eliminar el último byte del archivo PCL
truncate -s -1 "$FIXED_PCL_FILE"
if [ $? -ne 0 ]; then
echo "Error: Falló el ajuste del archivo PCL (eliminación del último byte)." >&2
exit 1
fi
# Verificar si el archivo ajustado se generó correctamente y no está vacío
if [ ! -s "$FIXED_PCL_FILE" ]; then
echo "Error: El archivo ajustado PCL está vacío o no se generó correctamente." >&2
exit 1
fi
# Limpiar archivos temporales
rm -f "TMP_FILE" "$QR_IMAGE" "$PCL_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment