Sotto ho inserito un nuovo g-script che ho creato per convertire immagini di formati png, jpg, gif. Non supporta la multi-conversione fra differenti formati per volta.
#!/bin/bash
#
# AUTHOR: Maurizio di NuvoleSparse
#
# License: GNU General Public version 2 or any later version.
# This program comes with ABSOLUTELY NO WARRANTY; for details
# see the COPYING file or visit "http://www.gnu.org/licenses/gpl.html".
# This is free software, and you are welcome to redistribute it under
# certain conditions. See the GPL license for details.
#
# Dependence:
# ImageMagick
# zenity
# functions
conversione()
{
if echo "$IMG" | grep -iqv ".$ESTENSIONE$"; then
ESTENSIONE_IMG=`echo "$IMG" | awk -F "." '{ print $NF }'`
NOME_IMG="$( echo `basename "$IMG"` | \
sed -e "s/.""$ESTENSIONE_IMG""$//" )"
[ -d "formato .$ESTENSIONE" ] || mkdir \
"formato .$ESTENSIONE"
# conversione
convert $QUALITY "$IMG" "formato .$ESTENSIONE"/\
"$NOME_IMG"."$ESTENSIONE" 2>>/tmp/gimageconvert.log | zenity \
--progress --text="'$NOME_IMG.$ESTENSIONE_IMG' in '$NOME_IMG.$ESTENSIONE'"\
--auto-close --pulsate
else
echo "La conversione dell'immagine '$IMG' e' stata\
saltata..." >>/tmp/gimageconvert.log
fi
}
usa_printf(){
inizio=0
fine=1024
p=1
while [ $p != ultima ]; do
printf "${temp:inizio:fine}" |
zenity --text-info --title="gimageconvert - \
parte $p" &
inizio=$(( inizio+1024 ))
fine_ipotetica=$(( inizio+fine ))
if [ ${#temp} -lt $fine_ipotetica ]; then
p="ultima"
printf "${temp:inizio:fine}" | zenity --text-info \
--title="gimageconvert - parte $p"
break
fi
p=$(( p+1 ))
done
}
##main
### trucco per evitare l'ostacolo di un path errato
### quando si avvia uno Gscript dalla Scrivania
PERCORSO="`echo $NAUTILUS_SCRIPT_CURRENT_URI| sed "s&^file://&&"`"
[ -n "$PERCORSO" ] && cd "$PERCORSO"
if [ $# -eq 0 ]; then
zenity --title="gimageconvert" --error --title="Attenzione"\
--text="Seleziona almeno un file."
exit 1
fi
FORMATO_DI_CONVERSIONE=`zenity --list --radiolist --title="gimageconvert"\
--text="Seleziona il formato in cui convertire." --column=Selez.\
--column=formato false Png false Jpg false Gif`
while [ $# -gt 0 ]; do
IMG=$1
case $FORMATO_DI_CONVERSIONE in
Png)
ESTENSIONE=png
[ -z "$QUALITY" ] && QUALITY="-quality `zenity --title\
"gimageconvert" --scale --min-value=0 --max-value=100 --value=95 --step 1\
--text "Scegli al qualità dell'immagine tra 0 e 100:"`"
conversione
;;
Jpg)
[ -z "$QUALITY" ] && QUALITY="-quality `zenity --title \
"gimageconvert" --scale --min-value=0 --max-value=100 --value=95 --step 1 \
--text "Scegli al qualità dell'immagine tra 0 e 100:"`"
ESTENSIONE=jpg
conversione
;;
Jpeg)
ESTENSIONE=jpg
[ -z "$QUALITY" ] && QUALITY="-quality `zenity --title \
"gimageconvert" --scale --min-value=0--max-value=100 --value=95 --step 1 \
--text "Scegli al qualità dell'immagine tra 0 e 100:"`"
conversione
;;
Gif)
ESTENSIONE=gif
conversione
;;
esac
shift
done
if [ -s "/tmp/gimageconvert.log" ]; then
echo -e "Lo script e' terminato." >>/tmp/gimageconvert.log
temp="$(cat "/tmp/gimageconvert.log")"
if [ ${#temp} -gt 1024 ]; then
usa_printf
else
cat "/tmp/gimageconvert.log" | zenity\
--title="Errore - gimageconvert"\
--text-info
fi
rm -f /tmp/gimageconvert.log || zenity --title="gimageconvert" --error\
--title="Attenzione"\
--text="Non e' stato possibile rimuovere il file /tmp/gimageconvert.log! :-("
else
zenity --title="gimageconvert" --info --text="Lo script e' terminato."
fi
exit 0
Ultimo aggiornamento 24 Ottobre 2008