Here's a little thing I whipped up to switch my desktop pattern in Gnome 2. I have some images in my wallpaper directory that I didn't want stretched because they were too small, so I check the size with Image::Size. This would be easily modified to center images with odd ratio sides so they won't be stretched.
- dystrophy -
#!/usr/bin/perl -w # by Darren Patterson # script to rotate bg in gnome 2 # easiest use is to run on startup or put in crontab use strict; use Image::Size; # minimum x and y dimension for image to stretch my $minx = 800; my $miny = 600; # location of backgrounds directory my $image_loc = "/home/darren/diamond/backup/My Documents/My Pictures" +; # debug? my $debug = 0; ################################ # end of configurables ############################### # open and read the image location dir opendir (IMGS, "$image_loc") || die "can't opendir $image_loc: $!"; my @files = grep {/(jpg|gif|bmp|png)$/} readdir (IMGS); closedir IMGS; # perlmonks help on srand ;-) srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); my $random = (int(rand $#files + 1)); # get the appropriate file my $file = $files[$random]; # debug help if ($debug) {print "$random - $file\n";} # Get the size of the file my ($xsize, $ysize) = imgsize("$image_loc/$file"); # set the bg first (otherwise it resizes the previous img before chang +ing) system("gconftool-2 --type=string --set /desktop/gnome/background/pict +ure_filename \"$image_loc/$file\""); # if dimensions are less than 800 x 600, center, else stretch it if ( $xsize < $minx || $ysize < $miny) { system("gconftool-2 --type=string --set /desktop/gnome/backgro +und/picture_options centered"); } else { system("gconftool-2 --type=string --set /desktop/gnome/backgro +und/picture_options stretched"); } exit;
- dystrophy -
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Rotate Wallpaper in Gnome 2
by dws (Chancellor) on Apr 04, 2003 at 23:41 UTC | |
Re: Rotate Wallpaper in Gnome 2
by benizi (Hermit) on Apr 05, 2003 at 04:40 UTC | |
by jonadab (Parson) on Apr 25, 2003 at 14:53 UTC | |
Re: Rotate Wallpaper in Gnome 2
by revdiablo (Prior) on Apr 04, 2003 at 23:21 UTC |
Back to
Cool Uses for Perl