现在任何智能手机拍摄的照片,有一个叫EXIF参数的东西,它包括光圈、快门、ISO、白平衡、日期时间、位置等各种图像数据,今天我们就利用代码来演示下从一张图片中能获得哪些意想不到的数据。
本文目录
一、什么是EXIF信息?二、读取图片信息1.引入jar包2.读取图片代码3.运行并打印图片信息4.分析
一、什么是EXIF信息?
EXIF(Exchangeable Image File format)是“可交换图像文件”的缩写,当中包含了专门为数码相机的照片而定制的元数据,可以记录数码照片的拍摄参数、缩略图及其他属性信息。
EXIF 所记录的元数据信息非常丰富,主要包含了以下几种信息:
- 拍摄日期
- 拍摄器材(机身、镜头、闪光灯等)
- 拍摄参数(快门速度、光圈F值、ISO速度、焦距、测光模式等)
- 图像处理参数(锐化、对比度、饱和度、白平衡等)
- 图像描述及版权信息
- GPS定位数据
- 缩略图
二、读取图片信息
先放一张前几天拍的图片,见下图:
待分析图片
1.引入jar包
<dependency>
<groupId>com.drewnoakesgroupId>
<artifactId>metadata-extractorartifactId>
<version>2.12.0version>
dependency>
2.读取图片代码
/**
*
* @Author: Java碎碎念
*
*/
@Test
public void readPic() {
System.out.println("开始读取图片信息...");
File jpegFile = new File("g:\\123.jpg");
Metadata metadata;
try {
metadata = JpegMetadataReader.readMetadata(jpegFile);
Iterator it = metadata.getDirectories().iterator();
while (it.hasNext()) {
Directory exif = it.next();
Iterator tags = exif.getTags().iterator();
while (tags.hasNext()) {
Tag tag = (Tag) tags.next();
System.out.println(tag);
}
}
System.out.println("图片信息读取完成!");
} catch (JpegProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
3.运行并打印图片信息
开始读取图片信息...
[JPEG] Compression Type - Baseline
[JPEG] Data Precision - 8 bits
[JPEG] Image Height - 3968 pixels
[JPEG] Image Width - 2976 pixels
[JPEG] Number of Components - 3
[JPEG] Component 1 - Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
[JPEG] Component 2 - Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JPEG] Component 3 - Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JFIF] Version - 1.1
[JFIF] Resolution Units - inch
[JFIF] X Resolution - 96 dots
[JFIF] Y Resolution - 96 dots
[JFIF] Thumbnail Width Pixels - 0
[JFIF] Thumbnail Height Pixels - 0
[Exif IFD0] Image Width - 2976 pixels
[Exif IFD0] Image Height - 3968 pixels
[Exif IFD0] Bits Per Sample - 8 8 8 bits/component/pixel
[Exif IFD0] Make - HUAWEI
[Exif IFD0] Model - STF-AL10
[Exif IFD0] Orientation - Unknown (0)
[Exif IFD0] X Resolution - 72 dots per inch
[Exif IFD0] Y Resolution - 72 dots per inch
[Exif IFD0] Resolution Unit - Inch
[Exif IFD0] Software - STF-AL10 9.1.0.201(C00E100R1P9)
[Exif IFD0] Date/Time - 2019:08:31 10:21:10
[Exif IFD0] YCbCr Positioning - Center of pixel array
[Exif IFD0] Device Setting Description - 105 112 112 0
[Exif SubIFD] Document Name -
[Exif SubIFD] Exposure Time - 269/500000 sec
[Exif SubIFD] F-Number - f/2.2
[Exif SubIFD] Exposure Program - Program normal
[Exif SubIFD] ISO Speed Ratings - 50
[Exif SubIFD] Exif Version - 2.10
[Exif SubIFD] Date/Time Original - 2019:08:31 10:21:10
[Exif SubIFD] Date/Time Digitized - 2019:08:31 10:21:10
[Exif SubIFD] Components Configuration - YCbCr
[Exif SubIFD] Compressed Bits Per Pixel - 0.95 bits/pixel
[Exif SubIFD] Shutter Speed Value - 1/999963864 sec
[Exif SubIFD] Aperture Value - f/2.2
[Exif SubIFD] Brightness Value - 0.0
[Exif SubIFD] Exposure Bias Value - 0 EV
[Exif SubIFD] Max Aperture Value - f/2.2
[Exif SubIFD] Metering Mode - Multi-segment
[Exif SubIFD] White Balance - Daylight
[Exif SubIFD] Flash - Flash did not fire
[Exif SubIFD] Focal Length - 4 mm
[Exif SubIFD] Makernote - 35 35 42 42 115 100 114 0
[Exif SubIFD] Sub-Sec Time - 579428
[Exif SubIFD] Sub-Sec Time Original - 579428
[Exif SubIFD] Sub-Sec Time Digitized - 579428
[Exif SubIFD] FlashPix Version - 1.00
[Exif SubIFD] Color Space - sRGB
[Exif SubIFD] Exif Image Width - 2976 pixels
[Exif SubIFD] Exif Image Height - 3968 pixels
[Exif SubIFD] Sensing Method - One-chip color area sensor
[Exif SubIFD] File Source - Digital Still Camera (DSC)
[Exif SubIFD] Scene Type - Directly photographed image
[Exif SubIFD] Custom Rendered - Custom process
[Exif SubIFD] Exposure Mode - Auto exposure
[Exif SubIFD] White Balance Mode - Auto white balance
[Exif SubIFD] Digital Zoom Ratio - 1
[Exif SubIFD] Focal Length 35 - 27 mm
[Exif SubIFD] Scene Capture Type - Standard
[Exif SubIFD] Gain Control - None
[Exif SubIFD] Contrast - None
[Exif SubIFD] Saturation - None
[Exif SubIFD] Sharpness - None
[Exif SubIFD] Subject Distance Range - Unknown
[Interoperability] Interoperability Index - Recommended Exif Interoperability Rules (ExifR98)
[Interoperability] Interoperability Version - 1.00
[GPS] GPS Version ID - 2.200
[GPS] GPS Latitude Ref - N
[GPS] GPS Latitude - 40° 0' 27.18"
[GPS] GPS Longitude Ref - E
[GPS] GPS Longitude - 116° 23' 8.97"
[GPS] GPS Altitude Ref - Below sea level
[GPS] GPS Altitude - 0 metres
[GPS] GPS Time-Stamp - 02:21:09.000 UTC
[GPS] GPS Processing Method - CELLID
[GPS] GPS Date Stamp - 2019:08:31
[Exif Thumbnail] Image Width - 384 pixels
[Exif Thumbnail] Image Height - 512 pixels
[Exif Thumbnail] Compression - JPEG (old-style)
[Exif Thumbnail] Orientation - Unknown (0)
[Exif Thumbnail] X Resolution - 72 dots per inch
[Exif Thumbnail] Y Resolution - 72 dots per inch
[Exif Thumbnail] Resolution Unit - Inch
[Exif Thumbnail] Thumbnail Offset - 8888 bytes
[Exif Thumbnail] Thumbnail Length - 26905 bytes
[Huffman] Number of Tables - 4 Huffman tables
[File] File Name - 123.jpg
[File] File Size - 2959902 bytes
图片信息读取完成!
4.分析
上面打印的日志信息比较多,我筛选了几个重要的图片信息如下:
[Exif IFD0] Make - HUAWEI
[Exif IFD0] Model - STF-AL10
[Exif IFD0] Software - STF-AL10 9.1.0.201(C00E100R1P9)
[Exif IFD0] Date/Time - 2019:08:31 10:21:10
[GPS] GPS Version ID - 2.200
[GPS] GPS Latitude Ref - N
[GPS] GPS Latitude - 40° 0' 27.18"
[GPS] GPS Longitude Ref - E
[GPS] GPS Longitude - 116° 23' 8.97"
从上面几个重要日志中,我们可以看到具体的拍照设备、时间以及经度和纬度信息。
有了经度和纬度,我们继续分析,打开网址http://www.gpsspg.com/maps.htm,输入上面的经度和纬度信息,我们来看看发生了什么,截图如下:
看到这张位置截图,我只想说,定位真是太精确了,这只是一张照片,如果多几张照片就能完整展示了一个人的踪迹,如果这些信息被有心之人利用,后果难以想象。
一张图片不只是一张简单的图片,里面有太多的附加信息,所以我们在公开场合发原图一定要慎重。
推荐阅读
1.Redis批量删除key的小技巧,你知道吗?
2.Spring Boot 2.X 如何快速整合jpa?
3.Spring Boot之Profile--快速搞定多环境使用与切换
4.Spring Boot 2.X整合Spring-cache,让你的网站速度飞起来
5.利用Spring Boot+WxJava实现网站集成微信登录功能
限时领取免费Java相关资料,涵盖了Java、Redis、MongoDB、MySQL、Zookeeper、Spring Cloud、Dubbo/Kafka、Hadoop、Hbase、Flink等高并发分布式、大数据、机器学习等技术。
关注下方公众号即可免费领取:
Java碎碎念公众号