我有一些通过分析生成的图像文件。每次我进行分析时,文件名都是相同的。我必须创建一个演示文稿,并且我正在使用 Libre Office Impress。 假设我有三个图像 image1.png、image2.png 和 image3.png,我应该将这些图像放在第 3 页、第 5 页和第 8 页
现在,我正在手动插入图像。我了解非常基本的 shell 脚本。所以我想知道什么是 bash shell 脚本来自动创建一个 libre office impress 文件,并在上述页面中自动插入图像。
最佳答案
如果 .odp 文件的主要部分没有改变,可以制作一个 flat openDocument 格式的模板,其中 3 个图像的名称由脚本更新。
平面文档是未压缩的xml文档,可以使用文本编辑器打开它来谨慎手动更改某些部分。通常此类文档的名称类似于 .fodp
您必须以平面格式保存此模板,并包含图像链接,而不是合并它们。
所以。 让我们说:
- 模板位于
/path/to/the/template.fodp
在示例的图像 im1.png、img2.png、img3.png 旁边。 - 第一张图片的名称是
image1.png
,第二个image2.png
,第三个:image3.png
. - 要导入的图片在同一个目录
/path/to/the/document
最终文件在哪里。
让我们编写一个脚本insertImages.sh
myTpl="$1" # will contains '/path/to/the/template.fodp'
myDir="$2" # will contains '/path/to/the/document'
img1="$3" # will contains the name of the first image in myDir
img2="$4" # will contains the name of the second image in myDir
img3="$5" # will contains the name of the third image in myDir
[[ -f "$1" ]] && cp "$1" "$2/document.fodp" || exit 1 # checks if the template exists and copy it
[[ -f "$3" ]] && sed "$2/document.fodp" "s/img1.png/$3/" || exit 1 # overwrite the name of the first image
[[ -f "$4" ]] && sed "$2/document.fodp" "s/img2.png/$4/" || exit 1 # overwrite the name of the second image
[[ -f "$5" ]] && sed "$2/document.fodp" "s/img3.png/$5/" || exit 1 # overwrite the name of the third image
这个脚本应该这样调用:
insertImages.sh "/path/to/the/template.fodp" "/path/to/the/document" "image1.png" "image2.png" "image3.png"
我不是一个大程序员。所以这些行中可能存在一些错误。但原则是有的。
它们是一些约束:
- 平面文档
- 图像的相对路径。
关于bash - 用于创建 libre office Impress 图像的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29884789/