Fedora15上實現桌面背景圖片漸變

       桌面背景圖片漸變,在Ubuntu中很容易實現。Ubuntu默認就自帶了幾款漸變壁紙。但換到Fedora後,貌似沒發現有自帶的漸變壁紙。
 拿Linux Deepin tool裏的deepin-wallpaper-xml-generator腳本實驗,發現和漸變一秒鐘的關係都沒有。因而fedora-wallpaper-xml-generator
 誕生了(其實Ubuntu裏早有漸變腳本了, http://blog.csdn.net/jxfgh/article/details/5900976 感謝他當初在ubuntu論壇裏告訴了俺)。
 折騰了半天終於有結果了,腳本以下:
#!/bin/bash
#
# 此腳本根據deepin-wallpaper-xml-generator改編而來。
# 用於生成Fedora15背景圖片漸變文件,也可適用於Ubuntu。
# 該腳本未經嚴格測試,一切由它引起的悲劇,本人概不負責,請謹慎操做。
# 20110705 by junwuwei@gmail.com
################################################################################
#名稱,可自定義
WALLPAPER_NAME="變形金剛漸變主題";
#圖片目錄,可自定義
WALLPAPER_DIR="/home/junwuwei/Pictures/backgrounds/變形金剛"
#漸變時間,漸變過程持續5秒。時間設置過短則看不到漸變效果。可自定義
DURATION_TIME="5.0"
#靜態圖片持續的時間。短一點能夠很快看到效果。可自定義
STATIC_DURATION_TIME="5.0"
################################################################################
#系統目錄,不建議更改
CONFIG_DIR="/usr/share/gnome-background-properties"
#生成圖片漸變xml文件,不建議更改
XML_FILE="$WALLPAPER_DIR/$WALLPAPER_NAME-1.xml"
#生成圖片漸變xml文件,不建議更改
XML_FILE_PROPERTIES="$CONFIG_DIR/$WALLPAPER_NAME.xml"


#### First check if we have write permissions to the share dirctory. ####
touch $CONFIG_DIR/testfile >/dev/null 2>/dev/null
if [[ $? -ne 0 ]]; then
   echo "**** 沒有權限在 $CONFIG_DIR 目錄下建立文件!****"
   exit 1
else
   rm $CONFIG_DIR/testfile 2>/dev/null
fi

#### Show the script description message. ###
cat <<EOF

################################################################################
     This script makes all pictures in the $WALLPAPER_DIR
     directory available to all users defined on this system as their
     system-wide GNOME wallpapers.

     This script should be run as "root" or with "sudo".
     e.g. sudo $0
################################################################################
EOF

#### Fail if the wallpaper directory does not exist. ####
if [[ ! -d $WALLPAPER_DIR ]]; then
    echo "**** 目錄 \"$WALLPAPER_DIR\" 不存在!****"
    exit 1
fi

#### Count the number of jpg/jpeg/png images. ####
numfiles=`ls -1 $WALLPAPER_DIR/*.jpg WALLPAPER_DIR/*.jpeg WALLPAPER_DIR/*.png 2>/dev/null | wc -l`

#### If there are no image files there then exit. ####
if [[ $numfiles -eq 0 ]]; then
    echo "**** 目錄 \"$WALLPAPER_DIR\" 下沒有任何圖片文件! ****"
    exit 1
fi

#### Now we create the XML file containing the images for backgrounds. ####
#### Start by creating the header in the XML file. ####
cat <<EOF > $XML_FILE_PROPERTIES
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
<wallpaper deleted="false">
<name>$WALLPAPER_NAME</name>
<name xml:lang="zh_CN">$WALLPAPER_NAME</name>
<filename>$XML_FILE</filename>
<options>zoom</options>
</wallpaper>
</wallpapers>
EOF
#### stretched  zoom
cat <<EOF > $XML_FILE
<background> 
<starttime>  
<year>2011</year>
<month>07</month>  
<day>05</day> 
<hour>12</hour>  
<minute>00</minute> 
<second>00</second>
</starttime>
<!--下面是圖片文件-->
EOF

#### Add each file to the XML file. ####
#### Doing it this way makes sure files with spaces in their names are ####
#### handled properly.   (ls .... | while read fname; do)              ####
from_file=
ls -1 $WALLPAPER_DIR/*.jpg $WALLPAPER_DIR/*.png $WALLPAPER_DIR/*.jpeg 2> /dev/null |
while read image_name; do
         echo $from_file
     if [ -f "$from_file" ]; then  
         echo "   Adding: `basename "$image_name"`."
         echo "  <static>"                                      >> $XML_FILE
         echo "     <duration>$STATIC_DURATION_TIME</duration>" >> $XML_FILE
         echo "     <file>$from_file</file>"                    >> $XML_FILE
         echo "  </static>"                                     >> $XML_FILE
         echo "  <transition>"                                  >> $XML_FILE
         echo "     <duration>$DURATION_TIME</duration>"        >> $XML_FILE
         echo "     <from>$from_file</from>"                    >> $XML_FILE
         echo "     <to>$image_name</to>"                       >> $XML_FILE
         echo "  </transition>"                                 >> $XML_FILE
        
     fi  

     from_file=$image_name
   

done

#### Create the footer for the XML file. ####
echo "</background>"                             >> $XML_FILE

#### Lastly display a message to inform caller to logout and back in. ####
cat <<EOF
################################################################################
     You're almost done. Log out and back in. Invoke the Desktop Background
     Change application again, and all your selected wallpapers should be
     available to use for all users.
################################################################################

EOF
 仍是oschina的編輯器爽,總算ok了.
 用sudo ./fedora-wallpaper-xml-generator.sh 執行此腳本後,可在系統工具》背景 選擇剛剛建立好的背景主題。
  截圖以下:
相關文章
相關標籤/搜索