第一步:引入依赖
<!-- 图片地理信息依赖 -->
<dependency>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
<version>2.11.0</version>
</dependency>
第二步:编写代码,获取信息
import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.hkwl.hkboot.smp.common.Ret;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
/**
* @Description:
* @Author Be.insighted
* @Date 2022/4/26 17:29
*/
@RestController
@Slf4j
public class ReadPictureInfoController {
@GetMapping("picture/info")
private Ret getPictureInfo() throws Exception {
printImageTags(new File("D://1.jpg"));
return Ret.success();
}
/**
* 读取照片里面的信息
*/
private static void printImageTags(File file) throws ImageProcessingException, Exception {
Metadata metadata = ImageMetadataReader.readMetadata(file);
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
String tagName = tag.getTagName(); //标签名
log.error("标签名: " + tagName);
String desc = tag.getDescription(); //标签信息
if (tagName.equals("Image Height")) {
System.out.println("图片高度: " + desc);
} else if (tagName.equals("Image Width")) {
System.out.println("图片宽度: " + desc);
} else if (tagName.equals("Date/Time Original")) {
System.out.println("拍摄时间: " + desc);
} else if (tagName.equals("GPS Latitude")) {
System.err.println("纬度 : " + desc);
System.err.println("纬度(度分秒格式) : "+pointToLatlong(desc));
} else if (tagName.equals("GPS Longitude")) {
System.err.println("经度: " + desc);
System.err.println("经度(度分秒格式): "+pointToLatlong(desc));
}
}
}
}
/**
* 经纬度格式 转换为 度分秒格式 ,如果需要的话可以调用该方法进行转换
*
* @param point 坐标点
* @return
*/
public static String pointToLatlong(String point) {
Double du = Double.parseDouble(point.substring(0, point.indexOf("°")).trim());
Double fen = Double.parseDouble(point.substring(point.indexOf("°") + 1, point.indexOf("'")).trim());
Double miao = Double.parseDouble(point.substring(point.indexOf("'") + 1, point.indexOf("\"")).trim());
Double duStr = du + fen / 60 + miao / 60 / 60;
return duStr.toString();
}
}
标签项:
2022-04-26 19:28:31.010 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Compression Type
2022-04-26 19:28:31.010 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Data Precision
2022-04-26 19:28:31.010 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Image Height
图片高度: 4344 pixels
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Image Width
图片宽度: 5792 pixels
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Number of Components
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Component 1
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Component 2
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Component 3
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Image Width
图片宽度: 5792 pixels
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Model
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Image Height
图片高度: 4344 pixels
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Orientation
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Date/Time
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: YCbCr Positioning
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Resolution Unit
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: X Resolution
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Y Resolution
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Make
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Unknown tag (0x9aaa)
2022-04-26 19:28:31.013 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: ISO Speed Ratings
2022-04-26 19:28:31.019 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exposure Program
2022-04-26 19:28:31.019 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: F-Number
2022-04-26 19:28:31.019 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exposure Time
2022-04-26 19:28:31.020 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Unknown tag (0x9999)
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Sensing Method
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Unknown tag (0x8895)
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Sub-Sec Time Digitized
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Sub-Sec Time Original
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Sub-Sec Time
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Focal Length
2022-04-26 19:28:31.024 ERROR 纬度 : 0° 0' 0"
纬度(度分秒格式) : 0.0
经度: 0° 0' 0"
经度(度分秒格式): 0.0
20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Flash
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: White Balance
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Metering Mode
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Scene Capture Type
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Focal Length 35
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Max Aperture Value
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Date/Time Digitized
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exposure Bias Value
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exif Image Height
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: White Balance Mode
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Date/Time Original
拍摄时间: 2022:04:24 18:23:22
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Brightness Value
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exif Image Width
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exposure Mode
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Aperture Value
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Components Configuration
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Color Space
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Scene Type
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Shutter Speed Value
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exif Version
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: FlashPix Version
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Interoperability Index
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Interoperability Version
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Latitude Ref
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Latitude
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Longitude Ref
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Longitude
2022-04-26 19:28:31.028 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Altitude Ref
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Altitude
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Time-Stamp
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Processing Method
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: GPS Date Stamp
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Thumbnail Offset
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Orientation
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Thumbnail Length
2022-04-26 19:28:31.030 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Compression
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Resolution Unit
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: X Resolution
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Y Resolution
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exif Image Height
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Exif Image Width
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: XMP Value Count
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Number of Tables
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Detected File Type Name
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Detected File Type Long Name
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Detected MIME Type
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: Expected File Name Extension
2022-04-26 19:28:31.032 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: File Name
2022-04-26 19:28:31.032 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: File Size
2022-04-26 19:28:31.032 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController : 标签名: File Modified Date