首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >水印png图像及其创建日期

水印png图像及其创建日期
EN

Stack Overflow用户
提问于 2021-11-29 07:10:08
回答 2查看 201关注 0票数 1

我需要水印我的png图像与其创建的日期。

我正在尝试阅读png文件exif data。但是在linux上使用screenshot工具捕获的screenshot文件没有exif数据。

我正在使用下面的脚本来为我的png图像加上创建日期的水印:

代码语言:javascript
复制
#!/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) -

代码语言:javascript
复制
2021-11-29T07:46:15+01:00

实际WaterMark格式输出:但是png图像stat没有这种格式,所以我的水印以-

代码语言:javascript
复制
2021-11-29 07:27

谁能建议我如何修改我的脚本,以获得预期的水印在我的png图像。

是否有其他最好的方法来水印png图像的日期创建。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-29 08:01:48

在Linux上,您可以获得如下所需的日期格式:

代码语言:javascript
复制
date=$(date -d "@$(stat -c %Y "$img")" --iso-8601=seconds)

  • stat -c %Y对output
  • %Y使用格式说明符是最后修改的日期,在epoch秒
  • GNU date -d @<epoch-seconds>中指定输入日期,@指定划时代秒格式
  • ,然后指定输出格式(--iso-8601=seconds)
  • BSD/Mac对stat

的语法略有不同

票数 1
EN

Stack Overflow用户

发布于 2021-11-29 07:39:44

请尝试在一个备用目录中的几个图片的副本,因为我还没有测试它。我认为exiftool将为您的图像添加文件修改日期,而不是EXIF DateTimeOriginal:

代码语言:javascript
复制
exiftool -v "-FileModifyDate>DateTimeOriginal" *.png

您可以看到与图像有关的所有时间相关数据的摘要,如下所示:

代码语言:javascript
复制
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一起放在搜索框中即可。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70150871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档