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!
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();
}
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!
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!
Maybe this could help you out? https://our.umbraco.com/packages/backoffice-extensions/media-info/
Thanks, I'll have a look - it absolutely reads the data I need, just gotta figure out how to access it!
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 useMetadataExtractor.Formats
to pull the specific directory you need (e.g. EXIF, IPTC, DICOM). Then instanceMetadataExtractor.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-dotnetYou 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!
Ha! Glad I could help!
is working on a reply...