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.
#!/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 -

In reply to Rotate Wallpaper in Gnome 2 by dystrophy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.