Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于格式化图像的脚本';来自Imagemagick的s EXIF输出_Imagemagick_Exif_Imagemagick Identify - Fatal编程技术网

用于格式化图像的脚本';来自Imagemagick的s EXIF输出

用于格式化图像的脚本';来自Imagemagick的s EXIF输出,imagemagick,exif,imagemagick-identify,Imagemagick,Exif,Imagemagick Identify,我需要从图像的EXIF元数据中获取一个包含信息的字符串。例如,我想: 摄像机模型,35毫米格式的焦距:24毫米,F11,1/500,ISO 200 我可以看到所有的信息从现在开始 identify-格式“%[EXIF:*]”image.jpg 但是,我在整合输出和生成信息方面遇到了问题 第一个问题是,'%[EXIF:]'打印所有EXIF数据,如果我用特定的EXIF标记替换星号,它不会打印任何内容。我知道我可以简单地将所有EXIF数据打印几次,然后使用grep获取我需要的数据,然后将它们组合在一起

我需要从图像的EXIF元数据中获取一个包含信息的字符串。例如,我想:

摄像机模型,35毫米格式的焦距:24毫米,F11,1/500,ISO 200

我可以看到所有的信息从现在开始

identify-格式“%[EXIF:*]”image.jpg

但是,我在整合输出和生成信息方面遇到了问题

第一个问题是,'%[EXIF:]'打印所有EXIF数据,如果我用特定的EXIF标记替换星号,它不会打印任何内容。我知道我可以简单地将所有EXIF数据打印几次,然后使用
grep
获取我需要的数据,然后将它们组合在一起,但只检索我正在寻找的值感觉更好

第二个问题,光圈值FNumber的格式类似于“63/10”,但我需要它为6.3;令人烦恼的是,快门速度曝光时间就像10/5000,我需要它是1/500。每种情况下我需要什么样的转换


谢谢

这里有一些东西可以帮助您开始使用
awk
查找EXIF关键字,并在它们经过时保存相应的设置。然后在
末尾
打印找到的所有内容:

#!/bin/bash

identify -format '%[EXIF:*]' a.jpg | awk -F= '
   /^exif:Model/                 {model=$2}
   /^exif:FocalLengthIn35mmFilm/ {focal=$2}
   /^exif:FNumber/               {f=$2}
   /^exif:ExposureTime/          {t=$2}
   /^exif:ISOSpeedRatings/       {ISO=$2}
   END {
      # Check if fNumber is a rational number and refactor if it is
      n=split(f,k,"/")
      if(n==2){
         f=sprintf("%.1f",k[1]/k[2]);
      }
      # Check if exposure time is a rational number and refactor if it is
      n=split(t,k,"/")
      if(n==2){
         m=int(k[2]/k[1]);
         t=sprintf("1/%d",m);
      }
      print model,focal,f,t,ISO
   }' OFS=,
样本输出

iPhone 4,35,2.8,1/914,80

我没有太广泛地测试从有理数的转换。。。在节日威士忌之间…

这里有一些东西可以让您开始使用
awk
查找EXIF关键字,并在它们经过时保存相应的设置。然后在
末尾
打印找到的所有内容:

#!/bin/bash

identify -format '%[EXIF:*]' a.jpg | awk -F= '
   /^exif:Model/                 {model=$2}
   /^exif:FocalLengthIn35mmFilm/ {focal=$2}
   /^exif:FNumber/               {f=$2}
   /^exif:ExposureTime/          {t=$2}
   /^exif:ISOSpeedRatings/       {ISO=$2}
   END {
      # Check if fNumber is a rational number and refactor if it is
      n=split(f,k,"/")
      if(n==2){
         f=sprintf("%.1f",k[1]/k[2]);
      }
      # Check if exposure time is a rational number and refactor if it is
      n=split(t,k,"/")
      if(n==2){
         m=int(k[2]/k[1]);
         t=sprintf("1/%d",m);
      }
      print model,focal,f,t,ISO
   }' OFS=,
样本输出

iPhone 4,35,2.8,1/914,80

我没有太广泛地测试从有理数的转换。。。在喜庆的威士忌之间……

在Imagemagick 6.9.9.29 Q16 Mac OSX中,这对我来说很好

infile="P1050001.JPG"
cameramodel=`identify -ping -format "%[EXIF:model]" "$infile"`
focallenght35=`identify -ping -format "%[EXIF:FocalLengthIn35mmFilm]" "$infile"`
fnumber1=`identify -ping -format "%[EXIF:FNumber]" "$infile" | cut -d/ -f1`
fnumber2=`identify -ping -format "%[EXIF:FNumber]" "$infile" | cut -d/ -f2`
exptime1=`identify -ping -format "%[EXIF:ExposureTime]" "$infile" | cut -d/ -f1`
exptime2=`identify -ping -format "%[EXIF:ExposureTime]" "$infile" | cut -d/ -f2`
isospeed=`identify -ping -format "%[EXIF:ISOSpeedRatings]" "$infile"`
fnumber=`echo "scale=1; $fnumber1/$fnumber2" | bc`
exptime=`echo "scale=3; $exptime1/$exptime2" | bc`
echo "CameraModel=$cameramodel, FocalLengthIn35mmFilm: $focallenght35 mm, F$fnumber, $exptime sec, ISO $isospeed"

CameraModel=DMC-FZ30,35毫米胶片的焦距:35毫米,F2.8,.125秒,ISO 200

或者

infile="P1050001.JPG"
declare `convert -ping "$infile" -format "cameramodel=%[EXIF:model]\n focallenght35=%[EXIF:FocalLengthIn35mmFilm]\n fnumber=%[EXIF:FNumber]\n exptime=%[EXIF:ExposureTime]\n isospeed=%[EXIF:ISOSpeedRatings]\n" info:`
fnumber1=`echo $fnumber | cut -d/ -f1`
fnumber2=`echo $fnumber | cut -d/ -f2`
fnumber=`echo "scale=1; $fnumber1/$fnumber2" | bc`
exptime1=`echo $exptime | cut -d/ -f1`
exptime2=`echo $exptime | cut -d/ -f2`
exptime=`echo "scale=0; $exptime2/$exptime1" | bc`
echo "CameraModel=$cameramodel, FocalLengthIn35mmFilm: $focallenght35 mm, F$fnumber, 1/$exptime sec, ISO $isospeed"


CameraModel=DMC-FZ30,35mm胶片的焦距:35mm,F2.8,1/8秒,ISO 200这对我来说在Imagemagick 6.9.9.29 Q16 Mac OSX中很好

infile="P1050001.JPG"
cameramodel=`identify -ping -format "%[EXIF:model]" "$infile"`
focallenght35=`identify -ping -format "%[EXIF:FocalLengthIn35mmFilm]" "$infile"`
fnumber1=`identify -ping -format "%[EXIF:FNumber]" "$infile" | cut -d/ -f1`
fnumber2=`identify -ping -format "%[EXIF:FNumber]" "$infile" | cut -d/ -f2`
exptime1=`identify -ping -format "%[EXIF:ExposureTime]" "$infile" | cut -d/ -f1`
exptime2=`identify -ping -format "%[EXIF:ExposureTime]" "$infile" | cut -d/ -f2`
isospeed=`identify -ping -format "%[EXIF:ISOSpeedRatings]" "$infile"`
fnumber=`echo "scale=1; $fnumber1/$fnumber2" | bc`
exptime=`echo "scale=3; $exptime1/$exptime2" | bc`
echo "CameraModel=$cameramodel, FocalLengthIn35mmFilm: $focallenght35 mm, F$fnumber, $exptime sec, ISO $isospeed"

CameraModel=DMC-FZ30,35毫米胶片的焦距:35毫米,F2.8,.125秒,ISO 200

或者

infile="P1050001.JPG"
declare `convert -ping "$infile" -format "cameramodel=%[EXIF:model]\n focallenght35=%[EXIF:FocalLengthIn35mmFilm]\n fnumber=%[EXIF:FNumber]\n exptime=%[EXIF:ExposureTime]\n isospeed=%[EXIF:ISOSpeedRatings]\n" info:`
fnumber1=`echo $fnumber | cut -d/ -f1`
fnumber2=`echo $fnumber | cut -d/ -f2`
fnumber=`echo "scale=1; $fnumber1/$fnumber2" | bc`
exptime1=`echo $exptime | cut -d/ -f1`
exptime2=`echo $exptime | cut -d/ -f2`
exptime=`echo "scale=0; $exptime2/$exptime1" | bc`
echo "CameraModel=$cameramodel, FocalLengthIn35mmFilm: $focallenght35 mm, F$fnumber, 1/$exptime sec, ISO $isospeed"


CameraModel=DMC-FZ30,35mm胶片的焦距:35mm,F2.8,1/8秒,ISO 200

更简单的是直接使用EXIFTOOL

infile="P1050001.JPG"
exiftool -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile"

Camera Model Name               : DMC-FZ30
Focal Length In 35mm Format     : 35 mm
F Number                        : 2.8
Exposure Time                   : 1/8
ISO                             : 200


更简单的方法是直接使用EXIFTOOL

infile="P1050001.JPG"
exiftool -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile"

Camera Model Name               : DMC-FZ30
Focal Length In 35mm Format     : 35 mm
F Number                        : 2.8
Exposure Time                   : 1/8
ISO                             : 200


jzxu写道:
这也很好,但是我注意到了参数 -csv,我如何去掉逗号并用空格替换它们

unix上的一种方法是使用tr将命令替换为空格,如下所示:

exiftool -csv -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile" | tr "," " "

SourceFile Model FocalLengthIn35mmFormat FNumber ExposureTime ISO
P1050001.JPG DMC-FZ30 35 mm 2.8 1/8 200

或者,如果不需要标题行:

exiftool -csv -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile" | tail -n +2 | tr "," " "

P1050001.JPG DMC-FZ30 35 mm 2.8 1/8 200

可能还有其他内部EXIFTOOL格式选项。看

我不是EXIFTOOL的专家,所以我可能错过了一些东西。但我没有看到以空格分隔的输出格式。但是,这会使输出采用制表符分隔的格式

infile="P1050001.JPG"
exiftool -s3 -T -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile"

DMC-FZ30    35 mm   2.8 1/8 200

因此可以使用tr将制表符替换为空格

exiftool -s3 -T -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile" | tr "\t" " "

DMC-FZ30 35 mm 2.8 1/8 200

jzxu写道:
这也很好,但是我注意到了参数 -csv,我如何去掉逗号并用空格替换它们

unix上的一种方法是使用tr将命令替换为空格,如下所示:

exiftool -csv -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile" | tr "," " "

SourceFile Model FocalLengthIn35mmFormat FNumber ExposureTime ISO
P1050001.JPG DMC-FZ30 35 mm 2.8 1/8 200

或者,如果不需要标题行:

exiftool -csv -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile" | tail -n +2 | tr "," " "

P1050001.JPG DMC-FZ30 35 mm 2.8 1/8 200

可能还有其他内部EXIFTOOL格式选项。看

我不是EXIFTOOL的专家,所以我可能错过了一些东西。但我没有看到以空格分隔的输出格式。但是,这会使输出采用制表符分隔的格式

infile="P1050001.JPG"
exiftool -s3 -T -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile"

DMC-FZ30    35 mm   2.8 1/8 200

因此可以使用tr将制表符替换为空格

exiftool -s3 -T -model -FocalLengthIn35mmFormat -FNumber -ExposureTime -ISO "$infile" | tr "\t" " "

DMC-FZ30 35 mm 2.8 1/8 200

你没有说你正在使用哪个版本的即时通讯;您没有显示您试图获取确切EXIF数据的代码。你也不要说你使用的是什么编程语言或操作系统。这些都会对你需要的答案产生影响;您没有显示您试图获取确切EXIF数据的代码。你也不要说你使用的是什么编程语言或操作系统。这些都会对您需要的答案产生影响。这也很好,但是,我注意到参数
-csv
,如何去掉逗号并用空格替换它们?这也很好,但是,我注意到参数
-csv
,如何去掉逗号并用空格替换它们?这几乎是完美的,有没有办法,比如说焦距的输出是
10/5000
,我希望它是
1/500
,而不是0.002?我已经在第二个例子中显示了曝光时间的划分为1/8秒。这几乎是完美的,有没有办法,假设焦距的输出是
10/5000
,我希望它是
1/500
,而不是0.002?我已经在第二个示例中显示了曝光时间的划分为1/8秒。感谢您的回答,它是有效的,尽管当曝光时间超过1秒和“1/%d”时可能会出现问题可能会搞砸。感谢您的回答,它是有效的,尽管当曝光时间超过一秒时可能会出现问题,并且“1/%d”可能会搞砸。