Domaine public πŸ…­

CMS minimal
ecrit avec VI

[ /  ^ < ]

QR code

prerequis       03/01/2025
automatiser       19/07/2022
gros fichiers       15/07/2022
decodage       29/08/2022
papier       17/07/2022
decoupe       13/07/2023

# si commnde qr absente : sudo apt-get install python3-qrcode
# si commande zbarimg absente : apt-get install zbar-tools
# si commande exiftool absente : apt-get install libimage-exiftool-perl
# exiv2 peut Γͺtre aussi

# pour les fichier non ascii (accents ) passer en base64


# la commande qr affiche le QR-Code en texte
# sauf si elle est redirigee au quel cas c'est du PNG
# pour recuperer le texte:
script coucou.qr.txt <<< "qr coucou"
# le contenu du fichier ne correspond pas Γ  l'affichage
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–„β–„β–„β–„β–„Β β–ˆβ–„Β Β Β β–„β–ˆΒ β–„β–„β–„β–„β–„Β β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–ˆΒ Β Β β–ˆΒ β–ˆβ–€β–ˆβ–€β–„β–„β–ˆΒ β–ˆΒ Β Β β–ˆΒ β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–ˆβ–„β–„β–„β–ˆΒ β–ˆΒ β–€Β β–„Β β–ˆΒ β–ˆβ–„β–„β–„β–ˆΒ β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–„β–„β–„β–„β–„β–ˆΒ β–€β–„β–ˆβ–„β–ˆβ–„β–„β–„β–„β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–„β–€β–€β–€β–„β–€β–„Β β–„β–€β–„β–ˆΒ Β Β β–„β–„Β β–ˆβ–€β–„β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–€β–€β–€Β Β β–„β–ˆΒ β–€β–„β–€Β β–„β–ˆβ–€β–ˆβ–ˆβ–„Β β–€β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–ˆβ–ˆβ–ˆβ–„β–„β–ˆΒ β–€Β Β β–€β–ˆβ–„β–„β–„Β β–€Β β–„β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–„β–„β–„β–„β–„Β β–ˆβ–„β–€β–„β–„β–ˆβ–€Β β–„Β β–ˆβ–ˆβ–„β–€β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–ˆΒ Β Β β–ˆΒ β–ˆβ–„Β β–ˆβ–ˆΒ Β Β Β β–€β–ˆβ–€β–€Β β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆΒ β–ˆβ–„β–„β–„β–ˆΒ β–ˆβ–ˆβ–„β–€β–€Β β–„β–ˆβ–ˆβ–„β–ˆβ–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–„β–„β–„β–„β–„β–ˆβ–„β–„β–„β–„β–ˆβ–ˆβ–„β–„β–„β–ˆβ–ˆβ–ˆβ–„β–ˆβ–ˆβ–ˆβ–ˆ
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€


# a partir de la version 7
qr --ascii coucou > fichier

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 
Β Β Β Β β–ˆβ–€β–€β–€β–€β–€β–ˆΒ β–€β–ˆβ–ˆβ–ˆβ–€Β β–ˆβ–€β–€β–€β–€β–€β–ˆΒ Β Β Β 
Β Β Β Β β–ˆΒ β–ˆβ–ˆβ–ˆΒ β–ˆΒ β–„Β β–„β–€β–€Β β–ˆΒ β–ˆβ–ˆβ–ˆΒ β–ˆΒ Β Β Β 
Β Β Β Β β–ˆΒ β–€β–€β–€Β β–ˆΒ β–ˆβ–„β–ˆβ–€β–ˆΒ β–ˆΒ β–€β–€β–€Β β–ˆΒ Β Β Β 
Β Β Β Β β–€β–€β–€β–€β–€β–€β–€Β β–ˆβ–„β–€Β β–€Β β–€β–€β–€β–€β–€β–€β–€Β Β Β Β 
Β Β Β Β β–€β–„β–„β–„β–€β–„β–€β–ˆβ–€β–„β–€Β β–ˆβ–ˆβ–ˆβ–€β–€β–ˆΒ β–„β–€Β Β Β Β 
Β Β Β Β β–ˆβ–„β–„β–„β–ˆβ–ˆβ–€Β β–ˆβ–„β–€β–„β–ˆβ–€Β β–„Β Β β–€β–ˆβ–„Β Β Β Β 
Β Β Β Β β–€β–€Β Β Β β–€β–€Β β–ˆβ–„β–ˆβ–ˆβ–„Β β–€β–€β–€β–ˆβ–„β–ˆβ–€Β Β Β Β 
Β Β Β Β β–ˆβ–€β–€β–€β–€β–€β–ˆΒ β–€β–„β–€β–€Β β–„β–ˆβ–€β–ˆΒ Β β–€β–„Β Β Β Β 
Β Β Β Β β–ˆΒ β–ˆβ–ˆβ–ˆΒ β–ˆΒ β–€β–ˆΒ Β β–ˆβ–ˆβ–ˆβ–ˆβ–„Β β–„β–„β–ˆΒ Β Β Β 
Β Β Β Β β–ˆΒ β–€β–€β–€Β β–ˆΒ Β β–€β–„β–„β–ˆβ–€Β Β β–€Β β–€Β Β Β Β Β Β 
Β Β Β Β β–€β–€β–€β–€β–€β–€β–€Β β–€β–€β–€β–€Β Β β–€β–€β–€Β Β Β β–€Β Β Β Β 
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 

# la commande "zint -b 58" produit aussi des QRcodes

# la commande zbarimg n'a pas besoin de beaucoup de contraste pour décoder
# mais ne lit pas les QRcode de couleur claire sur fond foncé
convert -negate image.png image.png

# pour annoter le fichier image:
convert image.png -pointsize 24 -gravity northeast -annotate +10+10 "en haut Γ  droite" -gravity southwest -annotate +10+10 "en bas Γ  gauche" image_a.png

#pour automatiser quand moins de 2ko
#!/bin/bash
# genere un QR code chiffrΓ©
CM='gpg -ca $FT'
DCM='gpg -d'
test "$1" = -n && shift && CM='ln -s $FT $FT.asc' DCM=cat # non chiffre
test -f "$*" || exec echo "# $0 : il faut un fichier en parametre" >&2
FT=$(mktemp)
cat "$*" > $FT
TITRE=$(head -1 $FT | tr \  _)-$(date +%Y%m%d)
eval $CM || exec echo "# $0 : la commande $(eval echo $CM) # plante"
qr < $FT.asc > $FT.png || exec echo "# $0 : qr < $FT.asc > $FT.png # plante" >&2
G="$(identify $FT.png | awk '{print $3}')" # important sinon montage de vignettes
montage -geometry $G -tile 2 $FT.png label:$TITRE $FT.jpg 
exiftool -Comment="QR-Code:$TITRE" $FT.jpg # gere mieux le JPG
echo -ne "# $0 : pour decoder : 
zbarimg --raw \"$*.jpg\" | head -n -1 > nom_de_fichier\n# $0 : " >&2
# zbarimg preffere le JPG
zbarimg --raw "$*.jpg" | head -n -1 | $DCM 2> /dev/null > $FT-recup
diff $FT $FT-recup || exec echo "# $0 : il y a une difference pour le fichier $*" >&2
test "$DCM" = cat || echo -e "# $0 : pour dechiffrer :\n$DCM nom_de_fichier" >&2

########## archiver l'image $FT.jpg

# en plus on peut y include de la steganograhie

zbarimg --raw $FT.jpg |  steghide embed -cf $FT.jpg -p mot_de_passe # obligatoire

steghide extract -sf $FT.jpg -xf - -p mot_de_passe # ou saisi

# au dessus de 2ko il faut decouper
FICHIER=petitsecret
gpg -ca $FICHIER
# max split -C 2000 $FICHIER.asc $FICHIER-x
split -l 16 $FICHIER.asc $FICHIER-x
# la commande qr produit du PNG ou sans destination de l'ASCII
for i in $FICHIER-x??; do
   (echo $i; cat $i) | qr > $i.png
   convert +append -rotate 90 $i.png label:".        $i" $i-l.png
done


rm in $FICHIER-x??

G="$(identify $FT.png | awk '{print $3}')" # important sinon montage de vignettes
montage -geometry $G -tile 1 $FICHIER-x??-l.png \
		$FICHIER.png
rm $FICHIER-x??.png
exiftool -Comment="mots de passe $(date +$FICHIER\ %Y/%m/%d)" $FICHIER.png

test "$DCM" = cat || echo -e "# $0 : pour dechiffrer :\n$DCM nom_de_fichier" >&2
# le standard exif ne fonctione qu'en JPG
convert $FICHIER.png $FICHIER.jpg
exiv2 -M"set Exif.Photo.UserComment charset=Ascii mots de passe $(date +$FICHIER\ %Y/%m/%d) $FICHIER.jpg

# verifier
zbarimg $FICHIER-$(date +%Y%m%d).png | grep ^QR-Code:

# pour dΓ©coder
zbarimg SCAN1762.JPG | awk -F : '$1 == "QR-Code" { print $2}'
# si abcdef-x??
FICHIER=abcdef
zbarimg $FICHIER.png | awk -F : '{if ($1 == "QR-Code") {PREFIX=$2} else {print PREFIX ":" 10000000 + NR ":" $0)}}' | sort | cut -d: -f3-
# ou bie
zbarimg --raw $FICHIER.png | awk '{if (/'$FICHIER'-x/) {SORTIE="'$FICHIER$(date +%Y%m%d)'-"$1} else {print $0 > SORTIE}}'
cat $FICHIER$(date +%Y%m%d)-$FICHIER-x?? | gpg -d 
rm $FICHIER$(date +%Y%m%d)-$FICHIER-x??


# pour l'impression sur papier
# ATTENTION avec un QR-Code de grande dimension
# agrandir légèrement pour occuper la page est contre productif
# car la taille des points n'est plus régulière

# pour un A4 en 300 dpi -greometry 2330

# pour anoter:
A="annotate +100+10"; convert -pointsize 120 -gravity northwest -$A "en haut Γ  gauche"  -gravity northeast -$A "en haut Γ  droite" -gravity southeast -$A "en bas Γ  droite" -gravity southwest -$A "en bas Γ  gauche" image.png image.png

# la commande qr accepte jusqu'Γ  30 lignes de base64
# et genere une image de 1850x1850
#Β si on veut agrandie 2220 ( 10 / 12 * )

# pour l'impressions 2 par page
ls *-l.png  | awk 'NR %2 == 1 { printf "convert -append %s ",$1}; NR %2 == 0 {print $1,"y" NR ".png;"}'
# imprimer avec gimp en pleine page
# pour le retour si pdf
convert recup.pdf recup.png
# si problème transformer en type couleur indexées avec 2 couleurs et flouter
convert -colors 2 -blur 10x1


# en cas de scan non lisible, essayer de rescanner en tournant le papier

# pour forcer la cooperation par exemple entre 4 personnes
#il peut etre interessant de decouper un QRcode pour le partager:

# prerequis ImageMagick
# definir H pour la hauteur et L pour la largeur du fichier qrcode.png
eval $(identify qrcode.png | awk '{print "H=" $3}' | sed 's/x/ L=/')

# annoter pour indiquer la position
convert qrcode.png -pointsize 24 -gravity northeast -annotate +10+10 "haut" -gravity northwest -annotate +10+10 "haut" -gravity southeast -annotate +10+10 "bas" -gravity southwest -annotate +10+10 "bas" qrcode_a.png

# decouper en 4
for i in 0 $(($H/2))
do for j in 0 $(($L/2))
   do convert qrcode_a.png -crop $(($H/2))x$(($L/2))+$i+$j +repage qrcode_$i-$j.png
   done
done

ƒraηcois✉memoρersο.ƒr