I wanted my Gnome wallpaper to switch through my picture collection randomly and also display only those pictures which are in landscape mode with an aspect ration about 16:9 or 16:10.
I didn't find anything doing it out of the box, but wallpapoz was a good start. It works fine, you can add singe pictures or directories to the configuration and even diferent sets for each workplace.
However it is boring to click thorugh a deep hierarchy of picture folders and subfolders to add pictures to the collection manually and there's still no possibility to take landscape pictures only.
So I had a look at the .wallpapoz/wallpapoz.xml file and realized how simple this file is structured. The files are listed line by line enclosed in a file tag.
Then I used the identify command line utility from ImageMagick package which prints out the pictures attributes like resolution - there I was, everything ready to write a shell script which woud go with find trough a given top level directory, execute the identify command on each image and pipe the output to awk which takes only JPEGs with a landscape aspect ratio 16:9 - 16:10 so 1.5 to 1.8. and print everything to a temporary file.
Then the skeleton of wallpapoz.xml with the desired preferences like randomize, stretch and scale are taken and echo'ed to the STDOUT as well as the contens of the temporary file containing the file listing.
As simply as that, copy the shell script somewhere and run it like:
wallpapoz.sh > ~/.wallpapoz.xml
and restart the daemon_wallpapoz.
And this is the script:
---- cut here ---
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` directory\ containing\ images OR"
echo "Usage: `basename $0` \"directory containing\images\""
exit 1
fi
TEMPFILE=/tmp/wallpapoz.tmp.$$
find "$*" -type f -exec identify {} \; 2>/dev/null \
| awk -F'JPEG|x' '
{
if(NF==4) {
split($3,arr," ");
if(arr[2]>arr[1]) {
ratio = arr[2]/arr[1];
if(ratio>1.5 && ratio <1.8) {
print $1;
}
}
}
}' \
| sed "s/ *$//g"|sed "s/^.*$/ <file><\/file>/g" > $TEMPFILE
echo '<?xml version="1.0" encoding="utf-8"?>'
echo '<!DOCTYPE Wallpapoz>'
echo '<wallpapoz interval="2" random="1" style="1" type="workspace">'
echo ' <workspace name="Umbenennen" no="1">'
cat $TEMPFILE
echo ' </workspace>'
echo ' <workspace name="Umbenennen" no="2">'
cat $TEMPFILE
echo ' </workspace>'
echo ' <workspace name="Umbenennen" no="3">'
cat $TEMPFILE
echo ' </workspace>'
echo ' <workspace name="Umbenennen" no="4">'
cat $TEMPFILE
echo ' </workspace>'
echo '</wallpapoz>'
rm $TEMPFILE
---- cut here ---
That's it!
I didn't find anything doing it out of the box, but wallpapoz was a good start. It works fine, you can add singe pictures or directories to the configuration and even diferent sets for each workplace.
However it is boring to click thorugh a deep hierarchy of picture folders and subfolders to add pictures to the collection manually and there's still no possibility to take landscape pictures only.
So I had a look at the .wallpapoz/wallpapoz.xml file and realized how simple this file is structured. The files are listed line by line enclosed in a file tag.
Then I used the identify command line utility from ImageMagick package which prints out the pictures attributes like resolution - there I was, everything ready to write a shell script which woud go with find trough a given top level directory, execute the identify command on each image and pipe the output to awk which takes only JPEGs with a landscape aspect ratio 16:9 - 16:10 so 1.5 to 1.8. and print everything to a temporary file.
Then the skeleton of wallpapoz.xml with the desired preferences like randomize, stretch and scale are taken and echo'ed to the STDOUT as well as the contens of the temporary file containing the file listing.
As simply as that, copy the shell script somewhere and run it like:
wallpapoz.sh > ~/.wallpapoz.xml
and restart the daemon_wallpapoz.
And this is the script:
---- cut here ---
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` directory\ containing\ images OR"
echo "Usage: `basename $0` \"directory containing\images\""
exit 1
fi
TEMPFILE=/tmp/wallpapoz.tmp.$$
find "$*" -type f -exec identify {} \; 2>/dev/null \
| awk -F'JPEG|x' '
{
if(NF==4) {
split($3,arr," ");
if(arr[2]>arr[1]) {
ratio = arr[2]/arr[1];
if(ratio>1.5 && ratio <1.8) {
print $1;
}
}
}
}' \
| sed "s/ *$//g"|sed "s/^.*$/ <file><\/file>/g" > $TEMPFILE
echo '<?xml version="1.0" encoding="utf-8"?>'
echo '<!DOCTYPE Wallpapoz>'
echo '<wallpapoz interval="2" random="1" style="1" type="workspace">'
echo ' <workspace name="Umbenennen" no="1">'
cat $TEMPFILE
echo ' </workspace>'
echo ' <workspace name="Umbenennen" no="2">'
cat $TEMPFILE
echo ' </workspace>'
echo ' <workspace name="Umbenennen" no="3">'
cat $TEMPFILE
echo ' </workspace>'
echo ' <workspace name="Umbenennen" no="4">'
cat $TEMPFILE
echo ' </workspace>'
echo '</wallpapoz>'
rm $TEMPFILE
---- cut here ---
That's it!
No comments:
Post a Comment