如何判断无扩展图像是png还是jpeg [英] How can I tell if an extensionless image is png or jpeg

查看:430
本文介绍了如何判断无扩展图像是png还是jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间我保存了一些由Web服务生成的图像,因此文件名为'ysauyft87ggsa67fgeg& w = 1600'。我可以打开并操作这些图像好吧,我只想知道它们是什么编码(几乎可以肯定是png或jpeg)。我在OSX中试过'获取信息',但它认为文件只是文本(即使它正确生成缩略图,我可以在预览中查看图像)。如果我在服务器上提供图像,它们将作为'application / octet-stream'传送。

A while ago I saved some images generated by a web service so the file names are e.g 'ysauyft87ggsa67fgeg&w=1600'. I can open and manipulate these images OK, I'd just like to know what encoding they are (it's almost certainly png or jpeg). I've tried 'get info' in OSX, but it thinks the files are just text (even though it generates thumbnails correctly and I can view the images in preview). If I serve the images on a server they are delivered as 'application/octet-stream'.

如何通过shell轻松确定它们是png还是jpeg?

How can I easily determine whether they are png or jpeg via the shell?

推荐答案

三种方法:

  • Open a file in a Hex editor (or just a binary file viewer). PNG files start with 'PNG', .jpg files should have 'exif'or 'JFIF' somewhere in the beginning.
  • Use file command: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/file.1.html For example: file 'ysauyft87ggsa67fgeg&w=1600'
  • Use identify file like torazaburo wrote in the comments (part of imagemagick lib)

这篇关于如何判断无扩展图像是png还是jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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