2015-09-20 72 views
2

我需要添加一些元数据到很多图像。例如,我需要将右眼和左眼的位置添加到元数据。 那就是这样的正义(291,493),lefteye(453,491)。我正在使用png文件。 gimp的例子给出了。 enter image description here 有没有什么好的方法可以将这些信息添加到图像元数据中?我见过keywords and strings in png文件。这是解决我的问题吗?另外我需要一个工具来编辑元数据。我有很多面部图像,我需要一个工具将这些元数据添加到每个图像。而且我还需要以编程方式从每个图像中检索这些数据。请提出解决所有这些任务的正确方法。添加和检索一些元数据到PNG图像

+0

你应该能够阅读和'ImageMagick'和'exiv2'写PNG元数据。这些参考文献可能有助于... http://dev.exiv2.org/projects/exiv2/wiki/The_Metadata_in_PNG_files和http://blog.client9.com/2007/08/19/editing-png-metadata-from-command -line.html –

+0

关闭?为什么??请首先阅读http://stackoverflow.com/help/on-topic ...程序员常用的软件工具;并且是 这是一个实用的,可回答的问题,它是软件开发所特有的。 – Neeraj

+0

工具建议不在话下。另外,除了你的问题太广泛了。 – usr2564301

回答

5

看起来您可以使用exiv2ImageMagick在PNG图像中设置注释,它们都具有命令行版本和C++库绑定。

所以,如果你这样做:

# Set image description using "exiv2" 
exiv2 -M"add Exif.Image.ImageDescription Ascii 'left eye (200,201) right eye(202,203)'" image.png 

# Set image comment usimg "ImageMagick" 
convert -comment "left eye(76,77) right eye(78,79)" image.png image.png 

现在你可以看一下结果与exiftool

exiftool image.png 

ExifTool Version Number   : 10.00 
File Name      : image.png 
Directory      : . 
File Size      : 496 bytes 
File Modification Date/Time  : 2015:09:20 20:45:29+01:00 
File Access Date/Time   : 2015:09:20 20:49:22+01:00 
File Inode Change Date/Time  : 2015:09:20 20:45:29+01:00 
File Permissions    : rw-r--r-- 
File Type      : PNG 
File Type Extension    : png 
MIME Type      : image/png 
Image Width      : 1 
Image Height     : 1 
Bit Depth      : 1 
Color Type      : Grayscale 
Compression      : Deflate/Inflate 
Filter       : Adaptive 
Interlace      : Noninterlaced 
White Point X     : 0.3127 
White Point Y     : 0.329 
Red X       : 0.64 
Red Y       : 0.33 
Green X       : 0.3 
Green Y       : 0.6 
Blue X       : 0.15 
Blue Y       : 0.06 
Background Color    : 1 
Modify Date      : 2015:09:20 20:45:29 
Exif Byte Order     : Little-endian (Intel, II) 
Image Description    : left eye (200,201) right eye(202,203) <--- HERE 
Comment       : left eye(76,77) right eye(78,79)   <--- HERE 
Datecreate      : 2015-09-20T20:45:29+01:00 
Datemodify      : 2015-09-20T20:45:29+01:00 
Exif Image Description   : left eye (200,201) right eye(202,203) 
Image Size      : 1x1 
Megapixels      : 0.000001 

或看与ImageMagickidentify命令的结果:

identify -verbose image.png 

    Format: PNG (Portable Network Graphics) 
    Mime type: image/png 
    Class: PseudoClass 
    Geometry: 1x1+0+0 
    Units: Undefined 
    Type: Bilevel 
    Base type: Bilevel 
    Endianess: Undefined 
    Colorspace: Gray 
    Depth: 8/1-bit 
    Channel depth: 
    gray: 1-bit 
    Channel statistics: 
    Pixels: 1 
    Gray: 
     min: 0 (0) 
     max: 0 (0) 
     mean: 0 (0) 
     standard deviation: 0 (0) 
     kurtosis: 0 
     skewness: 0 
     entropy: nan 
    Colors: 1 
    Histogram: 
     1: ( 0, 0, 0) #000000 gray(0) 
    Colormap entries: 2 
    Colormap: 
     0: ( 0, 0, 0) #000000 gray(0) 
     1: (255,255,255) #FFFFFF gray(255) 
    Rendering intent: Undefined 
    Gamma: 0.454545 
    Chromaticity: 
    red primary: (0.64,0.33) 
    green primary: (0.3,0.6) 
    blue primary: (0.15,0.06) 
    white point: (0.3127,0.329) 
    Background color: gray(255) 
    Border color: gray(223) 
    Matte color: gray(189) 
    Transparent color: gray(0) 
    Interlace: None 
    Intensity: Undefined 
    Compose: Over 
    Page geometry: 1x1+0+0 
    Dispose: Undefined 
    Iterations: 0 
    Compression: Zip 
    Orientation: Undefined 
    Properties: 
    comment: left eye(76,77) right eye(78,79)      <--- HERE 
    date:create: 2015-09-20T20:45:29+01:00 
    date:modify: 2015-09-20T20:45:29+01:00 
    exif:ImageDescription: left eye (200,201) right eye(202,203) <--- HERE 
    png:bKGD: chunk was found (see Background color, above) 
    png:cHRM: chunk was found (see Chromaticity, above) 
    png:IHDR.bit-depth-orig: 1 
    png:IHDR.bit_depth: 1 
    png:IHDR.color-type-orig: 0 
    png:IHDR.color_type: 0 (Grayscale) 
    png:IHDR.interlace_method: 0 (Not interlaced) 
    png:IHDR.width,height: 1, 1 
    png:text: 5 tEXt/zTXt/iTXt chunks were found 
    png:text-encoded profiles: 1 were found 
    png:tIME: 2015-09-20T20:45:29Z 
    signature: 709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c 
    Profiles: 
    Profile-exif: 70 bytes 
    Artifacts: 
    filename: image.png 
    verbose: true 
    Tainted: False 
    Filesize: 496B 
    Number pixels: 1 
    Pixels per second: 1PB 
    User time: 0.000u 
    Elapsed time: 0:01.000 
    Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-09-08 http://www.imagemagick.org 

或使用:

exiftool -s -Comment image.png 
Comment       : left eye(76,77) right eye(78,79) 

或者设定exiftool评论,并在以下两种方式之一ImageMagick阅读:

exiftool -comment="Crazy Comment" image.png 

identify -verbose image.png | grep Crazy 
comment: Crazy Comment 

identify -format "%[c]" image.png 
Crazy Comment 
相关问题