How can I get exif data from an image?


#1

Hey,

How can I get exif data from an image?

I am using ns-vue with iOS

Thanks


#2

is this what you are looking for


#3

That plugin looks perfect for Android but won’t work for iOS :-[


#4

Hi @xlcr, I’m working on a feature now that has me needing to get and set the Exif metadata of an Image. Here’s what I’ve learnt.

// The JPEG data of a UIImage
const data = UIImageJPEGRepresentation(image, 1.0)
// An image source constructed from the data
const source = CGImageSourceCreateWithData(data, null)
// The metadata bound to the source
const metadata =  CGImageSourceCopyPropertiesAtIndex(source, 0, null);

//Now lets say we have an image with the following metadata
{
  ColorModel = RGB;
  DPIHeight = 144;
  DPIWidth = 144;
  Depth = 8;
  Orientation = 1;
  PixelHeight = 1272;
  PixelWidth = 1272;
  ProfileName = "sRGB IEC61966-2.1";
  "{Exif}" = {
    ColorSpace = 1;
    PixelXDimension = 1272;
    PixelYDimension = 1272;
  };
  "{JFIF}" = {
    DensityUnit = 0;
    JFIFVersion =  (1, 0, 1 );
    XDensity = 144;
    YDensity = 144;
  };
  "{TIFF}" = {
    Orientation = 1;
    ResolutionUnit = 2;
    XResolution = 144;
    YResolution = 144;
  };
}

const keys = metadata.allKeys;
const exif_data = metadata.objectForKey("{Exif}");
/*
  keys -> (
    "{JFIF}",
    ProfileName,
    "{TIFF}",
    "{Exif}",
    ColorModel,
    PixelHeight,
    Depth,
    Orientation,
    PixelWidth
  )

  exif_data -> {
    ColorSpace = 1;
    PixelXDimension = 1272;
    PixelYDimension = 1272;
  }
*/

// Your can apply allKeys and objectForKey(...) to the exif_data object too.
const exif_keys = exif_data.allKeys;
const color_space = exif_data.objectForKey("ColorSpace");
/*
  exif_keys -> (
    ColorSpace,
    PixelXDimension,
    PixelYDimension
  )

  color_space -> 1
*/

Haven’t worked out how the set new key/values to “{Exif}” yet. I want to set the UserComment key with a custom “Message created on the fly”.