我需要水印我的png图像与其创建的日期。
我正在尝试阅读png文件exif data。但是在linux上使用screenshot工具捕获的screenshot文件没有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实际WaterMark格式输出:但是png图像stat没有这种格式,所以我的水印以-
2021-11-29 07:27谁能建议我如何修改我的脚本,以获得预期的水印在我的png图像。
或
是否有其他最好的方法来水印png图像的日期创建。
发布于 2021-11-29 08:01:48
在Linux上,您可以获得如下所需的日期格式:
date=$(date -d "@$(stat -c %Y "$img")" --iso-8601=seconds)stat -c %Y对output%Y使用格式说明符是最后修改的日期,在epoch秒date -d @<epoch-seconds>中指定输入日期,@指定划时代秒格式--iso-8601=seconds)stat的语法略有不同
发布于 2021-11-29 07:39:44
请尝试在一个备用目录中的几个图片的副本,因为我还没有测试它。我认为exiftool将为您的图像添加文件修改日期,而不是EXIF DateTimeOriginal:
exiftool -v "-FileModifyDate>DateTimeOriginal" *.png您可以看到与图像有关的所有时间相关数据的摘要,如下所示:
exiftool -time:all -G1 -a -s SOMEIMAGE.PNG
[System] FileModifyDate : 2021:11:23 09:48:30+00:00
[System] FileAccessDate : 2021:11:27 13:38:21+00:00
[System] FileInodeChangeDate : 2021:11:26 23:41:21+00:00如果您将exiftool标记添加到您的问题中,其中一位专家可能会建议您如何将其更改为仅在尚未出现的情况下添加数据。
此外,如果您有很多图像,请考虑使用GNU并行。只需将[gnu-parallel]与image一起放在搜索框中即可。
https://stackoverflow.com/questions/70150871
复制相似问题