Friday, May 25, 2012

Animated .gif as a background Ubuntu

Animated .gif as a background Ubuntu


This is a guide to getting an animated gif centered on your desktop background. I've only tested it in gnome on Hardy Heron. It works with or without compiz. The only caveat is that if you happen to have icons on your desktop the gif may cover these up if it's big enough.

Alright let's open a terminal window and get down to business.
We're going to grab Shantz modified (i.e. fixed) version of xwinwrap.
Ok we need the source from launchpad, but first we need to install bazaar to get the code, gcc to compile it, and gifsicle to actually display the gifs:
Code:
sudo apt-get install bzr build-essential gifsicle
Now let's grab the code:
Code:
bzr branch lp:xwinwrap
Let's change into that newly created directory and compile it and then install it.
Code:
cd xwinwrap
make
sudo make install
I've created a little script to make centering a gif easy for myself so open up your favorite text editor and copy and paste the following:
Code:
#!/bin/sh
# Uses xwinwrap to display given animated .gif in the center of the screen

if [ $# -ne 1 ]; then
    echo 1>&2 Usage: $0 image.gif
    exit 1
fi

#get screen resolution
SCRH=`xrandr | awk '/current/ { print $8 }'`
SCRW=`xrandr | awk '/current/ { print $10 }'`
SCRW=${SCRW%\,}

#get gif resolution
IMGHW=`gifsicle --info $1 | awk '/logical/ { print $3 }'`
IMGH=${IMGHW%x*}
IMGW=${IMGHW#*x}

#calculate position
POSH=$((($SCRH/2)-($IMGH/2)))
POSW=$((($SCRW/2)-($IMGW/2)))

xwinwrap -g ${IMGHW}+${POSH}+${POSW} -ov -ni -s -nf -- gifview -w WID $1 -a

exit 0
Save this file as gifbg.sh and let's not forget to make it executable:
Code:
chmod +x gifbg.sh
Now when we can make our background move:
Code:
./gifbg.sh /path/to/animated.gif
You'll probably want to start this script when you login so hit the gnome menu -> system -> preferences -> sessions hit Add and make up a name and copy the command into the appropriate box. Notes: You have to put the complete path to the script in here because gnome doesn't respect the $PATH variable. Also, for some reason the image will appear always on top when it's loaded from boot, one solution is to add a "sleep 5" on top of the script to make sure it loads after the rest of your desktop.

There you go, an animated background using a few megs of ram and an imperceptible amount of cpu time.

To stop the magic happening either Ctrl-C the command if you ran it from the terminal or hit Alt-F2 and type:
Code:
killall xwinwrap
To uninstall:
Code:
sudo rm /usr/bin/xwinwrap

5 comments:

  1. Can you help me please. I followed the instructions and it said that the file loaded ,but my desktop has no changes

    ReplyDelete
  2. how can I set the gif full screen?

    ReplyDelete
    Replies
    1. You can't do that, but you should get a gif background that fit to your screen resolution. check this out hdw.eweb4.com/search/animated+gif/

      Delete
  3. xwinwrap doesn't compile in Ubuntu 13.10.

    ReplyDelete
  4. It just paints over the whole x-screen. Is there a possibility to draw it only on the background?

    Using latest arch-linux.

    ReplyDelete