Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mike10004/jpeg-segment-finder

Java library to determine the offsets and lengths of metadata segments in a JPEG file.
https://github.com/mike10004/jpeg-segment-finder

Last synced: 15 days ago
JSON representation

Java library to determine the offsets and lengths of metadata segments in a JPEG file.

Awesome Lists containing this project

README

        

[![Travis build status](https://img.shields.io/travis/mike10004/jpeg-segment-finder.svg)](https://travis-ci.org/mike10004/jpeg-segment-finder)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.mike10004/jpeg-segment-finder.svg)](https://repo1.maven.org/maven2/com/github/mike10004/jpeg-segment-finder/)

# jpeg-segment-finder

Java library to determine the offsets and lengths of metadata segments in
a JPEG file. This library is intended to be small and not pull in a lot of
external dependencies. Use it if you want to *parse* JPEG metadata yourself
but don't want to *find* JPEG metadata yourself.

## Maven


com.github.mike10004
jpeg-segment-finder
0.5

## Usage

Find IPTC segments marked by byte 0xED:

JpegSegmentFinder finder = new JpegSegmentFinder();
List segments;
try (InputStream in = new FileInputStream(jpegFile)) {
segments = finder.findSegments(in, Collections.singleton((byte) 0xED));
}
JpegSegmentSpec iptc = segments.get(0);
byte[] jpegBytes = Files.readAllBytes(jpegFile.toPath());
int from = (int) iptc.contentOffset;
int to = from + (int) iptc.contentLength;
byte[] segmentBytes = Arrays.copyOfRange(jpegBytes, from, to);
// ...analyze those segments bytes as you please...

## Credits

Thank you to Drew Noakes for [metadata-extractor][metadata-extractor]. This
library is a hack on some classes in that library. The test image is from
that project's test resources.

[metadata-extractor]: https://github.com/drewnoakes/metadata-extractor