從技術的角度分析下為什麼不要在網上發“原圖”
現在任何智慧手機拍攝的照片,有一個叫EXIF引數的東西,它包括光圈、快門、ISO、白平衡、日期時間、位置等各種影象資料,今天我們就利用程式碼來演示下從一張圖片中能獲得哪些意想不到的資料。
本文目錄
一、什麼是EXIF資訊?二、讀取圖片資訊1.引入jar包2.讀取圖片程式碼3.執行並列印圖片資訊4.分析
一、什麼是EXIF資訊?
EXIF(Exchangeable Image File format)是“可交換影象檔案”的縮寫,當中包含了專門為數碼相機的照片而定製的元資料,可以記錄數碼照片的拍攝引數、縮圖及其他屬性資訊。
EXIF 所記錄的元資料資訊非常豐富,主要包含了以下幾種資訊:
- 拍攝日期
- 拍攝器材(機身、鏡頭、閃光燈等)
- 拍攝引數(快門速度、光圈F值、ISO速度、焦距、測光模式等)
- 影象處理引數(銳化、對比度、飽和度、白平衡等)
- 影象描述及版權資訊
- GPS定位資料
- 縮圖
二、讀取圖片資訊
先放一張前幾天拍的圖片,見下圖:
待分析圖片
1.引入jar包
<dependency>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
<version>2.12.0</version>
</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<Directory> it = metadata.getDirectories().iterator();
while (it.hasNext()) {
Directory exif = it.next();
Iterator<Tag> 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碎碎念公眾號