-
-
Save cryptostiltskin/119822319f5b93b6bbc9f1852573914e to your computer and use it in GitHub Desktop.
Script to generate QR code with data, and then place an overlay image on top of it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -eq "0" ] ; then | |
printf "Usage: %s [content] [overlay image] [output image]\n" "$0" | |
exit 1 | |
fi | |
content="$1" | |
overlayImage="$2" | |
outputImage="$3" | |
outputFilename=$(basename "${outputImage}") | |
qrencode --level=H --size=20 --output="/tmp/${outputFilename}" "${content}" | |
outputImageSize=$(identify -format "%w" "/tmp/${outputFilename}") | |
originalOverlayImageWidth=$(identify -format "%w" "${overlayImage}") | |
originalOverlayImageHeight=$(identify -format "%h" "${overlayImage}") | |
overlayImageWidth=$(( ${outputImageSize} / 3 )) | |
scaleFactor=$(echo "scale=2 ; ${overlayImageWidth} / ${originalOverlayImageWidth}" | bc -q) | |
overlayImageHeight=$(echo "scale=2 ; ${scaleFactor} * ${originalOverlayImageHeight}" | bc -q | cut -d '.' -f 1) | |
convert "${overlayImage}" -resize "${overlayImageWidth}x${overlayImageHeight}" "/tmp/overlay-resized.png" | |
composite -gravity center "/tmp/overlay-resized.png" "/tmp/${outputImage}" "${outputImage}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment