in reply to WallFortune
You should copy this code between the last constant definition and the next comment (#if you wish to use...)
Before using this new code, you should try the previous code, and see if it works ok. Then add this new part and call it when you start your system. Works nice, but might need some adjustments...## ***************** the SHIFTER ******************************* ## CHANGE THE DESKTOP BACKGROUND IMAGE... # dirIni = path to the directory where I have all the pictures to sor +t 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 **************************
You should change the directories and of course, the image name that is being displayed. This last one might not need to be changed if you have tryied the previous original code.
There is also a regex filter list of image file extensions that you might need to add/modify. It doesn't matter the extension since Image::Magick does the conversion to .BMP.
Please, read some info about how you might need to fine-tune Image::Magick on Windows (it is not that easy, but it works if you follow the recipy).
Thank you Koosemose for your inspiration!
|
|---|