## ***************** the SHIFTER ******************************* ## CHANGE THE DESKTOP BACKGROUND IMAGE... # dirIni = path to the directory where I have all the pictures to sort and choose one... my ($dirIni)='C:\Program files\Pictures\ImageCatcher'; # dirDesti= where I must record the new picture to write on it my ($dirDesti)='C:\Perl\guiones\images\Wallpaper1.bmp'; # tipos = valid image extensions of my pictures my ($tipos)= '\.jpg|\.gif|\.bmp|\.png|.\tif'; ##sort a list of valid images and return one with its complete path #sub nvaImagen { my (@ims); chdir($dirIni); opendir(DIR,$dirIni) or die("Cant open directory $dirIni $!"); ## grep filters & creates an array of valid pictures @ims = grep { $_ = "$dirIni/$_" if (/$tipos/ && -f "$dirIni/$_") ; $_ if (/$tipos/ && -f "$_"); } readdir(DIR); ##read every file closedir(DIR); ## the lotery... my ($ete)= int rand($#ims + .9999) if (@ims); my ($ima)= $ims[$ete] if ($ete && @ims); print "$ete - $ima\n"; ## checking the result ## reading the new image... my ($imobj, $er)=(Image::Magick->new,''); $er = $imobj->read($ima) if ($ima); die ("Error reading $ima [Img-Mgk] says: $er $!") if ($er); ## standarize an image size with IM $imobj->Resize(width=>800, height=>600, blur=>1); ## write the new image over the same old one $imobj->Write($dirDesti); } ## **********************/ the SHIFTER **************************