CopyCode The Code is as follows: <? PHP
/*
* Generate xml file for Ubuntu automatic switch Wallpaper
*/
// Image directory
$ Dir = '/home/Yuxing/background ';
$ Hd = opendir ($ DIR) or die ('can not open dir ');
$ Files = array ();
While ($ file = readdir ($ HD )){
$ TEM = "$ DIR/$ File ";
If (is_file ($ TEM) & in_array (strtolower (substr (strrchr ($ file ,'. '), 1), array ('jpg', 'gif ')))
$ Files [] = $ TEM;
}
Closedir ($ HD );
Unset ($ file );
$ XW = new xmlwriter ();
$ XW-> openmemory ();
$ XW-> setindent (true );
$ XW-> setindentstring ('');
$ XW-> startdocument ('1. 0', 'utf-8 ');
$ XW-> startelement ('background ');
$ XW-> startelement ('starttime ');
$ XW-> writeelement ('Year', '20140901 ');
$ XW-> writeelement ('month', '01 ');
$ XW-> writeelement ('day', '01 ');
$ XW-> writeelement ('hour ', '00 ');
$ XW-> writeelement ('minute ', '00 ');
$ XW-> writeelement ('second', '00 ');
$ XW-> endelement ();
$ COUNT = count ($ files );
For ($ I = 0; $ I <$ count; $ I ++ ){
$ XW-> startelement ('static ');
// $ XW-> writeelement ('duration', '2017. 0 ');
$ XW-> writeelement ('duration', '30. 0 ');
$ XW-> writeelement ('file', $ files [$ I]);
$ XW-> endelement ();
$ XW-> startelement ('transition ');
$ XW-> writeelement ('duration', '5 ');
$ XW-> writeelement ('from', $ files [$ I]);
$ XW-> writeelement ('to', isset ($ files [$ I + 1])? $ Files [$ I + 1]: $ files [0]);
$ XW-> endelement ();
}
$ XW-> endelement ();
$ Xml = $ XW-> outputmemory (true );
// Generate a file
$ Hd = fopen ($ dir. "/Yuxing. xml", 'wb ');
Fwrite ($ HD, $ XML );
Fclose ($ HD );
Echo 'OK ';
?>