-2

我从搅拌机创建图像,它们缺少我使用 bash 命令添加的 Exif 元数据exiv2。(因为传递这些图像的软件将使用元数据。)

例如,我可以使用将图像宽度设置为 960 exiv2 -M"set Exif.Image.ImageWidth 960" image.jpg,然后使用exiv2 -g Exif.Image.ImageWidth -Pv image.jpg.

为了快速总结,我可以exiv2 image.jpg获取一组 Exif 元数据的列表。这包括

$ exiv2 image.jpg
File name       : image.jpg
File size       : 32975 Bytes
MIME type       : image/jpeg
Image size      : 960 x 540

我如何使用它Image size来设置Exif.Image.ImageWidthExif.Image.ImageLength在 bash 中?

标准的Exif 标签不会列出ImageSize.

4

2 回答 2

1

正如 ghoti 所建议的,解析输出有效:

exiv2 image.jpg  | grep  "Image size" | sed -n "s/^.*Image size\s*:\s\([0-9]*\)\sx\s\([0-9]*\).*$/\1/p"

给出宽度,并且

exiv2 lowerCircle_0100.jpg  | grep  "Image size" | sed -n "s/^.*Image size\s*:\s\([0-9]*\)\sx\s\([0-9]*\).*$/\2/p"

高度。

不过,我仍然希望得到一个更清晰的答案。

sed 命令说明:

 sed -n "s/^.*Image size\s*:\s\([0-9].*\)\sx\s\([0-9]*\).*$/\1/p"

 -n            suppress printing
 "s/           substitute match
 ^.*           everything from the start
 Image size    until "Image size" is encountered
 \s*:\s        whitespace, colon, a single space
 ([0-9]*\)    any number of digits. store that in \1
 \sx\s         space x space
 ([0-9]*\)    another group of digits. store that in \2
 .*$           everything until the end of line
 /\1           substitute all that with the first group
 /p"           and print the substituted result
于 2018-10-11T08:32:42.043 回答
0

或没有 sed 象形文字

exiv2 pr  X.jpg | awk -F: '/Image size/ {print $2}' | cut -dx -f1 | tr -d ' '

exiv2 pr  X.jpg | awk -F: '/Image size/ {print $2}' | cut -dx -f2 | tr -d ' '
于 2019-01-20T13:22:27.477 回答