在Golang中检查HEIC文件格式

时间:2018-10-03 10:41:39

标签: image go heif heic

是否可以在Go中检查HEIC或HEIF文件格式?对于图像,我以前使用_, format, err := image.DecodeConfig(bytes.NewReader(file))检查文件是jpeg还是png。当检查HEIC文件时,它是完全空的。

1 个答案:

答案 0 :(得分:0)

如果您使用的是Linux或Mac,则可以使用mdls命令来获取文件类型。
示例:

$ mdls camel.heic

kMDItemBitsPerSample               = 32
kMDItemColorSpace                  = "RGB"
kMDItemContentCreationDate         = 2018-10-03 11:36:30 +0000
kMDItemContentCreationDate_Ranking = 2018-10-03 00:00:00 +0000
kMDItemContentModificationDate     = 2018-10-03 11:36:31 +0000
kMDItemContentType                 = "public.heic"
...

您可以在golang中运行以下命令,并获取kMDItemContentType的数据

out, err := exec.Command("mdls", "camel.heic").Output()
# parse data from `out`