¿Cómo puedo generar códigos QR con subtítulos?

¿Cómo puedo generar códigos QR con subtítulos?

Necesito generar varios miles de códigos qr de identificaciones simples (1234, 1235, 1236, ...) y quiero poder hacerlos también legibles para humanos. qrencodees una herramienta realmente genial para generar códigos qr, PERO no hay forma de agregar un subtítulo allí.

¿Algunas ideas?

Respuesta1

Cree una imagen con el texto y agréguela a la imagen:

#!/bin/bash

txt="$1"
qrencode -o "$txt".png "$txt"

convert  -pointsize 36 "label:$txt" "$txt.gif"
convert -append "$txt".png "$txt.gif" "$txt.total.gif"

Respuesta2

Imagemagics convertal rescate:

  1. generar código QR con qrencode(salida PNG, SVG no funciona con conversión, creo)
  2. generar una imagen png a partir de una cadena conconvert
  3. agregar las imágenes con convert

Aquí el script para esto:

for i in $(cat ../input.csv); do 
  qrencode $i -t png -l H -s 10 -o $i.q.png;
  convert -size 290x40 xc:white -pointsize 34 -gravity center -font /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf -draw "text 0,0 '$i'" $i.s.png; 
 convert -append $i.q.png $i.s.png $i.png; rm $i.q.png; rm $i.s.png; 
 echo $i; 
done;

DejaVuSansMono.ttf tiene puntos entre ceros, lo que lo hace bien legible, puede haber otros. 1 y L pequeña y los sospechosos habituales también son claramente discernibles.

Respuesta3

Si desea mantener el formato svg, parece que no es tan difícil editar el xml para agregar un nuevo <text>elemento al final del archivo. No conozco svg lo suficiente como para hacer esto de alguna manera estándar, pero al observar cómo se ve el archivo cuando usas un editor de svg para agregar una línea de texto, el siguiente awkscript podría ser suficiente para el ejemplo que diste.

i=1234
qrencode "$i" -t svg -l H -s 10 -o "$i.q.svg.orig"
awk <"$i.q.svg.orig" >"$i.q.svg" -v txt="$i" '
/<svg /{ match($0,"height=\"([0-9.]+)",grp)
    ht = grp[1]*1.1
    ht = "height=\"" ht
    sub("height=\"([0-9.]+)",ht,$0)
    match($0,"viewBox=\"0 0 ([0-9]+) ([0-9]+)",grp)
    vb = int(grp[2]*1.1+.5)
    x = int(grp[1]/2+.5)
    y = grp[2]+1
    vb = "viewBox=\"0 0 " grp[1] " " vb
    sub("viewBox=\"0 0 ([0-9]+) ([0-9]+)",vb,$0)
}
/<rect x="0" /{
    match($0,"height=\"([0-9.]+)",grp)
    ht = int(grp[1]*1.1+.5)
    ht = "height=\"" ht
    sub("height=\"([0-9.]+)",ht,$0)
}
/<\/svg>/{
    printf "  <text font-family=\"Helvetica, sans-serif\" font-size=\"6\" stroke-width=\"0\" text-anchor=\"middle\" x=\"%d\" y=\"%d\" xml:space=\"preserve\">%s</text>",x,y,txt
}
{print}
'

Esto es más complejo de lo realmente necesario, por ser un poco más genérico.

Toma el inicial <svg width="10.23cm" height="10.23cm" viewBox="0 0 29 29" ...y aumenta la altura y los valores del cuarto viewBox en un 10% para que se convierta en <svg width="10.23cm" height="11.23cm" viewBox="0 0 29 33" ....

Luego toma el rectángulo blanco de fondo y aumenta la altura de manera similar desde <rect ... height="29"hasta <rect ... height="33".

Finalmente, agrega una <text...>línea antes del final, usando como posiciones xey los valores encontrados en viewBox. Centra text-anchor="middle"el texto en esta coordenada.

información relacionada