public BufferedImage getExifThumbnail() throws ImagingException, IOException {

        if (exif == null) {
            return null;
        }

        final List<? extends ImageMetadataItem> dirs = exif.getDirectories();
        for (final ImageMetadataItem d : dirs) {
            final TiffImageMetadata.Directory dir = (TiffImageMetadata.Directory) d;
            // Debug.debug("dir", dir);
            BufferedImage image = dir.getThumbnail();
            if (null != image) {
                return image;
            }

            final JpegImageData jpegImageData = dir.getJpegImageData();
            if (jpegImageData != null) {
                // JPEG thumbnail as JPEG or other format; try to parse.
                boolean imageSucceeded = false;
                try {
                    image = Imaging.getBufferedImage(jpegImageData.getData());
                    imageSucceeded = true;
                } catch (final IOException ignored) { // NOPMD
                } finally {
                    // our JPEG reading is still a bit buggy -
                    // fall back to ImageIO on error
                    if (!imageSucceeded) {
                        final ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.getData());
                        image = ImageIO.read(input);
                    }
                }
                if (image != null) {
                    return image;
                }
            }
        }

        return null;
    }
Gets the thumbnail image if available.

@return the thumbnail image. May be {@code null} if no image could be found.
@throws ImagingException if it fails to read the image
@throws IOException      if it fails to get the thumbnail or to read the image data
src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java