15janv. 2011
Du texte à l'image
15:10 - Par Alexis - Informatique
J'avais besoin de faire une image contenant uniquement du texte. Je suis passé d'un script mal écrit, sans paramètres et absolument pas utilisable autrement que pour un unique besoin à un script un peu moins mal écrit, avec paramètres.
Si ça peut servir à d'autres qu'à moi, tant mieux. Alors voici mon code :
#!/bin/bash # Check parameters if [ $# -ne 6 ] then echo "This script need 6 parameters to run" echo "Usage: $0 file content font color bgcolor density" echo " - file: path to the output file" echo " - content: path to the file containing the content to convert into an image" echo " - font: path to the font to use" echo " - color: text color" echo " - bgcolor: background and border color" echo " - density: size of the text" exit 1 fi FILE=$1 if [ -e $2 ] then CONTENT=$2 else echo "The content file don't exist" exit 2 fi if [ -e $3 ] then FONT=$3 else echo "The font file don't exist" exit 3 fi COLOR=$4 BACKGROUND=$5 DENSITY=$6 TEMP=/tmp/Temp.Text.To.Image.png # Create the image rm $FILE while read LINE do convert -fill $COLOR -density $DENSITY -font $FONT -trim +repage -border 5 -bordercolor $BACKGROUND -background $BACKGROUND text:- $TEMP <<< $LINE if [ -e $FILE ] then montage -tile 1x2 -background $BACKGROUND -geometry +0+0 $FILE $TEMP $FILE else mv $TEMP $FILE fi done < $CONTENT rm $TEMP
Il est également disponible en téléchargement.