Fedora15上实现桌面背景图片渐变

柔情痞子 提交于 2020-03-09 11:52:55
       桌面背景图片渐变,在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 执行此脚本后,可在系统工具》背景 选择刚刚创建好的背景主题。
  截图如下:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!