我找到了几个可以创建幻灯片的软件应用程序,但我还没有看到一个支持更改图像大小(即适合、拉伸、填充宽度、填充高度)的软件。有支持此功能的软件吗?
答案1
介绍
事情是这样的:如果你在终端中运行dconf watch /
,同时浏览 Ubuntu 设置中的壁纸大小选项(平铺、比例、缩放等),你会看到以下内容:
/org/gnome/desktop/background/picture-options
'zoom'
/org/gnome/desktop/background/picture-options
'wallpaper'
/org/gnome/desktop/background/picture-options
'centered'
/org/gnome/desktop/background/picture-options
'scaled'
/org/gnome/desktop/background/picture-options
'stretched'
/org/gnome/desktop/background/picture-options
'spanned'
这是什么意思?这意味着如果你有一个可以翻看壁纸的软件,它也应该能够翻看这些选项,对吗?
嗯,我写了一张壁纸之前的幻灯片脚本。过去它有必需的选项。针对您的具体问题,我修改了脚本以处理大小,并且只设置了一个必需的选项,-d
该选项对应于幻灯片图像应该存放的目录。
基本用法
使用方法很简单:给它一个包含图像的目录,给它一个大小,然后运行。就像这样做一样简单:
$ ./xml_wallpaper_maker.py -s zoom -d ~/Pictures/wallpapers/
您始终可以使用-h
选项来显示额外选项的帮助信息,以防您忘记用法:
$ ./xml_wallpaper_maker.py -h
usage: xml_wallpaper_maker.py [-h] -d DIRECTORY [-t TRANSITION] [-l LENGTH]
[-o] [-s SIZE]
Serg's XML slideshow creator
optional arguments:
-h, --help show this help message and exit
-d DIRECTORY, --directory DIRECTORY
Directory where images stored. Required
-t TRANSITION, --transition TRANSITION
transition time in seconds, default 2.5
-l LENGTH, --length LENGTH
Time length in seconds per image, default 1800
-o, --overlay Enables use of overlay transition
-s SIZE, --size SIZE wallpaper,zoom,centered,scaled,stretched,or spanned
脚本源
脚本源代码可在此处和此处获取GitHub。如果您有git
,请随意git clone https://github.com/SergKolo/sergrep.git
从上面的链接运行或下载存储库文件。如果您从这里复制,请确保将文件另存为 ,xml_wallpaper_maker.py
并使用 使其可执行chmod +x xml_wallpaper_maker.py
。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Author: Serg Kolo , contact: [email protected]
# Date: September 2 , 2016
# Purpose: A program that creates and launches XML slideshow
#
# Tested on: Ubuntu 16.04 LTS
#
#
# Licensed under The MIT License (MIT).
# See included LICENSE file or the notice below.
#
# Copyright © 2016 Sergiy Kolodyazhnyy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from gi.repository import Gio
import xml.etree.cElementTree as ET
import lxml.etree as etree
import argparse
import sys
import os
def gsettings_set(schema, path, key, value):
"""Set value of gsettings schema"""
if path is None:
gsettings = Gio.Settings.new(schema)
else:
gsettings = Gio.Settings.new_with_path(schema, path)
if isinstance(value,list ):
return gsettings.set_strv(key, value)
if isinstance(value,int):
return gsettings.set_int(key, value)
if isinstance(value,str):
return gsettings.set_string(key,value)
def parse_args():
""" Parses command-line arguments """
arg_parser = argparse.ArgumentParser(
description='Serg\'s XML slideshow creator',
)
arg_parser.add_argument(
'-d', '--directory',
help='Directory where images stored. Required',
type=str,
required=True
)
arg_parser.add_argument(
'-t','--transition',
type=float,
default=2.5,
help='transition time in seconds, default 2.5',
required=False
)
arg_parser.add_argument(
'-l','--length',
type=float,
default=1800.0,
help='Time length in seconds per image, default 1800',
required=False
)
arg_parser.add_argument(
'-o','--overlay',
action='store_true',
help='Enables use of overlay transition',
required=False
)
arg_parser.add_argument(
'-s','--size',
type=str,
help='wallpaper,zoom,centered,scaled,stretched,or spanned',
default='scaled',
required=False
)
return arg_parser.parse_args()
def main():
""" Program entry point"""
args = parse_args()
xml_file = os.path.join(os.path.expanduser('~'),'.local/share/slideshow.xml')
path = os.path.abspath(args.directory)
duration = args.length
transition_time = args.transition
if not os.path.isdir(path):
print(path," is not a directory !")
sys.exit(1)
filepaths = [os.path.join(path,item) for item in os.listdir(path) ]
images = [ img for img in filepaths if os.path.isfile(img)]
filepaths = None
images.sort()
root = ET.Element("background")
previous = None
# Write the xml data of images and transitions
for index,img in enumerate(images):
if index == 0:
previous = img
continue
image = ET.SubElement(root, "static")
ET.SubElement(image,"duration").text = str(duration)
ET.SubElement(image,"file").text = previous
if args.overlay:
transition = ET.SubElement(root,"transition",type='overlay')
else:
transition = ET.SubElement(root,"transition")
ET.SubElement(transition,"duration").text = str(transition_time)
ET.SubElement(transition, "from").text = previous
ET.SubElement(transition, "to").text = img
previous = img
# Write out the final image
image = ET.SubElement(root, "static")
ET.SubElement(image,"duration").text = str(duration)
ET.SubElement(image,"file").text = previous
# Write out the final xml data to file
tree = ET.ElementTree(root)
tree.write(xml_file)
# pretty print the data
data = etree.parse(xml_file)
formated_xml = etree.tostring(data, pretty_print = True)
with open(xml_file,'w') as f:
f.write(formated_xml.decode())
gsettings_set('org.gnome.desktop.background',None,'picture-options', args.size)
gsettings_set('org.gnome.desktop.background',None,'picture-uri','file://' + xml_file)
if __name__ == '__main__':
main()