Package com.drew.metadata

Examples of com.drew.metadata.Metadata


    public void readJPEGMeta(String image_path)
            throws java.lang.InterruptedException
    {
        File jpegDosya = new File(image_path);
        Metadata metadata=null;

        try{
            metadata = JpegMetadataReader.readMetadata(jpegDosya);
        }catch(Exception e){
            return;
        }

        //Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
        StringBuffer exifBuf = new StringBuffer();

        // iterate through metadata directories
        Iterator directories = metadata.getDirectoryIterator();
        while (directories.hasNext()) {
            Directory directory = (Directory)directories.next();
            // iterate through tags
            Iterator tags = directory.getTagIterator();
            while (tags.hasNext()) {
View Full Code Here


            File file = new File(filePath);

            if (!wikiFormat && argList.size()>1)
                System.out.println("***** PROCESSING: " + filePath);

            Metadata metadata = null;
            try {
                metadata = ImageMetadataReader.readMetadata(file);
            } catch (Exception e) {
                e.printStackTrace(System.err);
                System.exit(1);
            }
            long took = System.nanoTime() - startTime;
            if (!wikiFormat)
                System.out.println("Processed " + (file.length()/(1024d*1024)) + "MB file in " + (took / 1000000d) + "ms");

            if (wikiFormat) {
                String fileName = file.getName();
                String urlName = fileName.replace(" ", "%20"); // How to do this using framework?
                ExifIFD0Directory exifIFD0Directory = metadata.getOrCreateDirectory(ExifIFD0Directory.class);
                String make = escapeForWiki(exifIFD0Directory.getString(ExifIFD0Directory.TAG_MAKE));
                String model = escapeForWiki(exifIFD0Directory.getString(ExifIFD0Directory.TAG_MODEL));
                System.out.println();
                System.out.println("-----");
                System.out.println();
                System.out.printf("= %s - %s =%n", make, model);
                System.out.println();
                System.out.printf("<a href=\"http://metadata-extractor.googlecode.com/svn/sample-images/%s\">%n", urlName);
                System.out.printf("<img src=\"http://metadata-extractor.googlecode.com/svn/sample-images/%s\" width=\"300\"/><br/>%n", urlName);
                System.out.println(fileName);
                System.out.println("</a>");
                System.out.println();
                System.out.println("|| *Directory* || *Tag Id* || *Tag Name* || *Tag Description* ||");
            }

            // iterate over the exif data and print to System.out
            for (Directory directory : metadata.getDirectories()) {
                for (Tag tag : directory.getTags()) {
                    String tagName = tag.getTagName();
                    String directoryName = directory.getName();
                    String description = tag.getDescription();

                    if (wikiFormat) {
                        System.out.printf("||%s||0x%s||%s||%s||%n",
                                escapeForWiki(directoryName),
                                Integer.toHexString(tag.getTagType()),
                                escapeForWiki(tagName),
                                escapeForWiki(description));
                    }
                    else
                    {
                        System.out.printf("[%s] %s = %s%n", directoryName, tagName, description);
                    }
                }

                // print out any errors
                for (String error : directory.getErrors())
                    System.err.println("ERROR: " + error);
            }

            if (args.length > 1 && thumbRequested) {
                ExifThumbnailDirectory directory = metadata.getDirectory(ExifThumbnailDirectory.class);
                if (directory!=null && directory.hasThumbnailData()) {
                    System.out.println("Writing thumbnail...");
                    directory.writeThumbnail(args[0].trim() + ".thumb.jpg");
                } else {
                    System.out.println("No thumbnail data exists in this image");
View Full Code Here

    }

    @NotNull
    public static Metadata extractMetadataFromJpegSegmentReader(@NotNull JpegSegmentData segmentReader)
    {
        final Metadata metadata = new Metadata();

        // Loop through looking for all SOFn segments.  When we find one, we know what type of compression
        // was used for the JPEG, and we can process the JPEG metadata in the segment too.
        for (byte i = 0; i < 16; i++) {
            // There are no SOF4 or SOF12 segments, so don't bother
            if (i == 4 || i == 12)
                continue;
            // Should never have more than one SOFn for a given 'n'.
            byte[] jpegSegment = segmentReader.getSegment((byte)(JpegSegmentReader.SEGMENT_SOF0 + i));
            if (jpegSegment == null)
                continue;
            JpegDirectory directory = metadata.getOrCreateDirectory(JpegDirectory.class);
            directory.setInt(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE, i);
            new JpegReader().extract(new ByteArrayReader(jpegSegment), metadata);
            break;
        }
View Full Code Here

public class PsdMetadataReader
{
    @NotNull
    public static Metadata readMetadata(@NotNull File file) throws IOException
    {
        Metadata metadata = new Metadata();

        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");

        try {
            new PsdReader().extract(new RandomAccessFileReader(randomAccessFile), metadata);
View Full Code Here

    }

    @NotNull
    public static Metadata readMetadata(@NotNull InputStream inputStream, boolean waitForBytes) throws IOException
    {
        Metadata metadata = new Metadata();

        byte[] headerBytes = new byte[26];
        inputStream.read(headerBytes, 0, 26);

        new PsdReader().extract(new ByteArrayReader(headerBytes), metadata);
View Full Code Here

public class TiffMetadataReader
{
    @NotNull
    public static Metadata readMetadata(@NotNull File file) throws IOException
    {
        Metadata metadata = new Metadata();

        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");

        try {
        new ExifReader().extractTiff(new RandomAccessFileReader(randomAccessFile), metadata);
View Full Code Here

        int b;
        // TODO do this in chunks rather than byte-by-byte, and honour 'waitForBytes'
        while((b = inputStream.read()) != -1) {
            out.write(b);
        }
        Metadata metadata = new Metadata();
        new ExifReader().extractTiff(new ByteArrayReader(out.toByteArray()), metadata);
        return metadata;
    }
View Full Code Here

    @Nullable
    public static Geolocation getGeolocation(@Nullable final byte[] imageBytes) throws ImageProcessingException, IOException {
        if (imageBytes != null && imageBytes.length > 0) {

            final Metadata metadata = ImageMetadataReader.readMetadata(new BufferedInputStream(new ByteArrayInputStream(imageBytes)), false);
            if (metadata != null) {
                final GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
                if (gpsDirectory != null) {
                    return new GeolocationImpl(gpsDirectory);
                }
            }
        }
View Full Code Here

     Attemps to read a thumbnail from EXIF headers
     @return The thumbnail image or null if none available
     */
    private BufferedImage readExifThumbnail( File f ) {
        BufferedImage bi = null;
        Metadata metadata = null;
        try {
            metadata = JpegMetadataReader.readMetadata( f );
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
        ExifDirectory exif = null;
        if ( metadata != null && metadata.containsDirectory( ExifDirectory.class ) ) {
            try {
                exif = (ExifDirectory) metadata.getDirectory( ExifDirectory.class );
                byte[] thumbData = exif.getThumbnailData();
                if ( thumbData != null ) {
                    ByteArrayInputStream bis = new ByteArrayInputStream( thumbData );
                    try {
                        bi = ImageIO.read( bis );
View Full Code Here

        try {
            URL url = href.toURL();
            URLConnection connection = url.openConnection();
            InputStream stream = connection.getInputStream();
            Metadata metadata = JpegMetadataReader.readMetadata(stream);

            TreeWriter tree = new TreeWriter(runtime);
            tree.startDocument(step.getNode().getBaseURI());
            tree.addStartElement(c_metadata);
            tree.addAttribute(_href, href.toASCIIString());
            tree.startContent();

            // iterate through metadata directories
            Iterator<Directory> directories = metadata.getDirectories().iterator();
            while (directories.hasNext()) {
                Directory directory = directories.next();
                String dir = directory.getName();
                Iterator<Tag> tags = directory.getTags().iterator();
                while (tags.hasNext()) {
View Full Code Here

TOP

Related Classes of com.drew.metadata.Metadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.