有没有办法推断文件的图像格式,而不读取整个文件? [英] Is there a way to infer what image format a file is, without reading the entire file?

查看:98
本文介绍了有没有办法推断文件的图像格式,而不读取整个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种很好的方法可以查看图像的格式,而无需将整个文件读入内存?

Is there a good way to see what format an image is, without having to read the entire file into memory?

显然这会因格式而异(我对TIFF文件特别感兴趣)但是什么样的程序对于确定文件的图像格式是有用的是否无需读取整个文件?

Obviously this would vary from format to format (I'm particularly interested in TIFF files) but what sort of procedure would be useful to determine what kind of image format a file is without having to read through the entire file?

BONUS :如果图像是Base64编码的字符串怎么办?在解码之前推断它的任何可靠方法吗?

BONUS: What if the image is a Base64-encoded string? Any reliable way to infer it before decoding it?

推荐答案

大多数图像文件格式在开始时都有唯一的字节。 unix 文件命令查看文件的开头以查看它包含的数据类型。请参阅有关文件中的幻数 magicdb.org

Most image file formats have unique bytes at the start. The unix file command looks at the start of the file to see what type of data it contains. See the Wikipedia article on Magic numbers in files and magicdb.org.

这篇关于有没有办法推断文件的图像格式,而不读取整个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆