从 JPEG EXIF 元数据更改文件创建日期

Fin*_*Ove 46 image-manipulation images exif file-metadata

上传到 ftp 站点时,原始文件创建日期似乎丢失了,而我得到了上传日期。但是,文件中的 Exif 数据是正确的。是否有工具可以从 Exif 日期批量更改创建日期?

Vol*_*gel 39

EXIF 处理工具exiv2有一个内置选项:

exiv2 -T rename image.jpg
Run Code Online (Sandbox Code Playgroud)

将上次文件修改的时间设置为 mtime存储在 EXIF 元数据中的日期。

您要求使用创建时间 - 但在类 Unix 系统中没有使用,这是有充分理由的

我很确定您调用 create time 的时间实际上是mtime,没问题。

来自man exiv2

NAME
  exiv2 - Image metadata manipulation tool

SYNOPSIS
  exiv2 [options] [action] file ...

DESCRIPTION
  exiv2 is a program to read and write Exif, IPTC and XMP image metadata and image com?
  ments. The following image formats are supported:

[ ... ]

mv | rename
 Rename files and/or set file timestamps according to the Exif create time?
 stamp.  Uses  the  value  of  tag  Exif.Photo.DateTimeOriginal  or, if not
 present, Exif.Image.DateTime to determine the timestamp. The filename for?
 mat can be set with -r fmt, timestamp options are -t and -T.

[ ... ]

-T  Only  set  the  file  timestamp according to the Exif create timestamp, do not
    rename the file (overrides -k). This option is only  used  with  the  'rename'
    action.  Note:  On Windows you may have to set the TZ environment variable for
    this option to work correctly.
Run Code Online (Sandbox Code Playgroud)

请参阅-t相反的选项。


小智 12

假设,正如“Volker Siegel”所提到的,你可能是指 mtime,我会简单地使用 exiftools 内置函数..

喜欢:

 $ exiftool "-DateTimeOriginal>FileModifyDate" test.jpg
Run Code Online (Sandbox Code Playgroud)

这将采用“exif 字段”DateTimeOriginal”信息并使用它来设置文件“test.jpg”的文件系统修改日期/时间信息。

例子:

$ ls -la test.jpg
-rw-r-----@ 1 user  18329968  2432451 14 Out 17:57 test.jpg

$ exiftool -DateTimeOriginal test.jpg
Date/Time Original              : 2015:10:09 13:29:58
 
$ exiftool "-DateTimeOriginal>FileModifyDate" test.jpg
    1 image files updated
 
$ ls -la test.jpg
-rw-r-----@ 1 user  18329968  2432451  9 Out 13:29 test.jpg
Run Code Online (Sandbox Code Playgroud)


Sky*_*RaT 9

也可以使用以下jhead命令制作:

$ jhead -ft file.jpg
Run Code Online (Sandbox Code Playgroud)

手册页

-ft 将文件的系统时间戳设置为存储在 Exif 标头中的时间戳。

-dsft 将 Exif 时间戳设置为文件的时间戳。需要 Exif 标头预先存在。-mkexif如果需要,使用选项创建一个。

  • jhead 似乎是*唯一的* EXIF 工具,它不会与 EXIF 标头混淆 - exiftool 和 exiv2 实际上 *增加* 文件的大小并移动标头,这对我来说是完全不可接受的。 (4认同)
  • 对于 Jhead 3.0,选项是 `-dsft`。`-ft` 正好相反。 (2认同)

Joe*_*lor 8

如果您从 CPAN 安装 exiftool,您可以运行以下脚本,假设您的所有文件都在名为“all”的目录中

#!/bin/sh
for i in all/*; do
    SPEC=`exiftool -t -s -d "%Y-%m-%d %H:%M:%S" -CreateDate "$i"`
    read X DATE <<<${SPEC}
    echo "$i:$DATE"
    touch -d "$DATE" "$i"
done
Run Code Online (Sandbox Code Playgroud)


kro*_*owe 5

ExifTool 可以读取和操作大多数 EXIF 信息,包括提取日期/时间原始或创建数据 EXIF 标签。您可以使用此信息来重命名文件或更改其时间戳。例如:

find -name '*.jpg' | while read PIC; do
    DATE=$(exiftool -p '$DateTimeOriginal' $PIC |
    sed 's/[: ]//g')
    touch -t $(echo $DATE | sed 's/\(..$\)/\.\1/') $PIC
done
Run Code Online (Sandbox Code Playgroud)

这将查找当前目录中的所有 JPG 文件并更新时间戳。

如果您还想根据该日期为这些文件命名(这往往会派上用场),那么还要mv -i $PIC $(dirname $PIC)/$DATE.jpg在该done行之前添加。