Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim Bennett 23 posts 155 karma points
    Oct 07, 2020 @ 12:03
    Tim Bennett
    0

    Populate Properties with EXIF data

    Hi!

    I'd like to populate custom media type properties with already extant EXIF/IPTC data, but that is utter witchcraft and I have no idea where to even start!

    Any suggestions greatly appreciated!

  • DonZalmrol 220 posts 833 karma points
    Oct 07, 2020 @ 16:20
  • Tim Bennett 23 posts 155 karma points
    Oct 07, 2020 @ 23:50
    Tim Bennett
    0

    Thanks, I'll have a look - it absolutely reads the data I need, just gotta figure out how to access it!

  • Tim Bennett 23 posts 155 karma points
    Oct 27, 2020 @ 12:16
    Tim Bennett
    101

    Thought I'd come back and post the solution I used in the end for the benefit of anyone else searching.

    I used Drew Noakes' Metadata Extractor library: https://github.com/drewnoakes/metadata-extractor-dotnet

    Here's some example code to extract IPTC data. In a nutshell, you pass a physical path for your file to ImageMetadataReader.ReadMetadata to get a handle on the set of directories that hold each type of metadata, then use MetadataExtractor.Formats to pull the specific directory you need (e.g. EXIF, IPTC, DICOM). Then instance MetadataExtractor.Formats.xxxx.xxxxDescriptor , where the xxxx refers to your chosen metadata type, and you can then extract the specific values for metadata tags. The exception is Adobe XMP data, which is stored a bit differently, but our man Drew Noakes has you covered: https://github.com/drewnoakes/xmp-core-dotnet

    @using MetadataExtractor    
    var image = Model.Value<IPublishedContent>("Image");
    <!-- get physical path of image -->
    var physicalPath = Server.MapPath(image.Url);
    <!-- get IPTC metadata -->
    var directories = ImageMetadataReader.ReadMetadata(physicalPath);
    var IptcDir = directories.OfType<MetadataExtractor.Formats.Iptc.IptcDirectory>().FirstOrDefault();
    if (IptcDir != null) 
        {
             var descriptor = new MetadataExtractor.Formats.Iptc.IptcDescriptor(IptcDir);
             // get IPTC values
             String IptcCopyright= descriptor.GetCopyrightNoticeDescription();
             String IptcSource= descriptor.GetSourceDescription();
        }
    
  • DonZalmrol 220 posts 833 karma points
    Oct 28, 2020 @ 14:38
    DonZalmrol
    1

    You son of a gun! Thanks to your pasted code I was able to do this for my site as well! :)

    In another topic of mine I was overthinking this and trying to use the Metadata extractor from Drew Noakes also but trying to use a surface controller to pass the data along...

    But clearly it was possible to do it from Umbraco directly without the need of a surface controller.

    Many thanks for pointing me in the right direction!

  • Tim Bennett 23 posts 155 karma points
    Oct 28, 2020 @ 16:09
    Tim Bennett
    0

    Ha! Glad I could help!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies