【发布时间】:2022-01-06 01:50:50
【问题描述】:
我需要用创建日期为我的 png 图像添加水印。
我正在尝试读取png 文件exif data。但是在linux上使用screenshot工具捕获的png文件没有exif数据。
我正在使用以下脚本为我的 png 图像添加水印及其创建日期:
#!/bin/bash
echo "Script for addding time stamp"
date --iso-8601=seconds
shopt -s extglob
find . -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.tif" -o \
-iname "*.tiff" -o -iname "*.png" |
## Go through the results, saving each as $img
while IFS= read -r img; do
## Find will return full paths, so an image in the current
## directory will be ./foo.jpg and the first dot screws up
## bash's pattern matching. Use basename and dirname to extract
## the needed information.
name=$(basename "$img")
path=$(dirname "$img")
ext="${name/#*./}";
## Check whether this file has exif data
if exiv2 "$img" 2>&1 | grep timestamp >/dev/null
## If it does, read it and add the water mark
then
echo "Processing $img...";
convert "$img" -gravity SouthEast -pointsize 22 -fill black \
-annotate +30+30 %[exif:DateTimeOriginal] \
"$path"/"${name/%.*/.time.$ext}";
## If the image has no exif data, use the creation date of the file.
else
echo "No Exif data in $img...";
date=$(stat "$img" | grep Modify | cut -d ' ' -f 2,3 | cut -d ':' -f1,2)
convert "$img" -gravity SouthEast -pointsize 22 -fill black \
-annotate +30+30 "$date" \
"$path"/"${name/%.*/.time.$ext}";
fi
done
预期的水印格式输出:
但我需要具有以下日期格式的水印(如其输出$ date --iso-8601=seconds)-
2021-11-29T07:46:15+01:00
实际水印格式输出:
但是png图片stat没有这种格式,所以我的水印是-
2021-11-29 07:27
谁能建议我如何修改我的脚本以在我的 png 图像上获得预期的水印。
或
还有其他最好的方法来为 png 图像添加水印及其创建日期。
【问题讨论】: