How to get image details like creation timestamp using MiniMagic
Public
26 Aug 09:43

How to get image details like creation date and tile using MiniMagic

First you have to access image exif:

# having a path to image
exif = MiniMagick::Image.open(/path/to/image).exif
# or having an image
exif = MiniMagick::Image.read(image).exif

Then you have access to a hash containing image details that looks more less like this:

{
  "ApertureValue"=>"2159/1273",
  "BrightnessValue"=>"1961/192",
  "ColorSpace"=>"65535",
  "ComponentsConfiguration"=>"1, 2, 3, 0",
  "DateTime"=>"2018:08:23 09:54:24",
  "DateTimeDigitized"=>"2018:08:23 09:54:24",
  "DateTimeOriginal"=>"2018:08:23 09:54:24",
  "ExifImageLength"=>"3024",
  "ExifImageWidth"=>"4032",
  "ExifOffset"=>"194",
  "ExifVersion"=>"0221",
  "ExposureBiasValue"=>"0/1",
  "ExposureMode"=>"0",
  "ExposureProgram"=>"2",
  "ExposureTime"=>"1/1919",
  "Flash"=>"24",
  "FlashPixVersion"=>"0100",
  "FNumber"=>"9/5",
  "FocalLength"=>"399/100",
  "FocalLengthIn35mmFilm"=>"28",
  "ISOSpeedRatings"=>"20",
  "Make"=>"Apple",
  "MakerNote"=>"...",
  "MeteringMode"=>"5",
  "Model"=>"iPhone 8",
  "Orientation"=>"1",
  "ResolutionUnit"=>"2",
  "SceneCaptureType"=>"0"
}

CAUTION: Be careful when parsing DateTime and other timestamps because using Time.parse(exif['DateTime']) won’t work - you have change : to - in date part first

Comments

Empty! You must sign in to add comments.