推荐下 apache 的 common imaging 库

经常用 tika 做文件类型识别,可以支持很多种文件类型。

<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>2.6.0</version>
</dependency>

但最近需要获取图片文件的更多信息,tika 实现不了,发现 apache 的 imaging 库,可以获取详细的图片信息:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-imaging</artifactId>
    <version>1.0-alpha3</version>
</dependency>

除了获取图片的宽高信息,还能获取 EXIF、压缩算法(CompressionAlgorithm)、颜色类型(ColorType)、mimeType、实际物理像素比等,速度很快,挺方便的。

一行代码实现:

public ImageInfo getInfo(MultipartFile file) {
    return Imaging.getImageInfo(file.getBytes());
}
java·image·apache
98 views
Comments
登录后评论
Sign In