[英]Check For HEIC File Format in Golang
Is there a way to check for HEIC or HEIF file format in Go? 有没有一种方法可以检查Go中的HEIC或HEIF文件格式? For images, I was previously using _, format, err := image.DecodeConfig(bytes.NewReader(file))
to check if a file was a jpeg or png. 对于图像,我以前使用_, format, err := image.DecodeConfig(bytes.NewReader(file))
来检查文件是jpeg还是png。 When checking against a HEIC file, it's completely empty. 当检查HEIC文件时,它是完全空的。
if you are in Linux or Mac then you can use the mdls
command to get the file type. 如果您使用的是Linux或Mac,则可以使用mdls
命令获取文件类型。
example : 例如:
$ 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"
...
you can run the following command within golang
and get the data for kMDItemContentType
您可以运行中的以下命令golang
并获得数据kMDItemContentType
out, err := exec.Command("mdls", "camel.heic").Output()
# parse data from `out`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.