Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created May 16, 2020 03:59
Show Gist options
  • Save michaellwest/3c8f9a09b72c8cb51328555bcb0a2817 to your computer and use it in GitHub Desktop.
Save michaellwest/3c8f9a09b72c8cb51328555bcb0a2817 to your computer and use it in GitHub Desktop.
Read EXIF orientation using Sitecore PowerShell Extensions.
# https://exiftool.org/TagNames/EXIF.html
# https://stackoverflow.com/questions/27835064/get-image-orientation-and-rotate-as-per-orientation
# http://fredericiana.com/2013/05/23/imagetwist-exif-rotation-addon/
# https://www.cyotek.com/blog/handling-the-orientation-exif-tag-in-images-using-csharp
enum ExifOrientation {
RotateNoneFlipNone = 1
Rotate90FlipX = 5
Rotate90FlipNone = 6
}
#[System.Drawing.RotateFlipType]::Rotate90FlipNone
$exifOrientationTagId = 0x0112
$item = Get-Item -Path "master:" -ID "{C852E80E-ED49-4354-A397-6F66487F0E26}"
$mediaItem = [Sitecore.Data.Items.MediaItem]$item
$blobField = $mediaItem.InnerItem.Fields["blob"]
$mediaStream = $blobField.GetBlobStream()
$loadedImage = [System.Drawing.Image]::FromStream($mediaStream)
if($loadedImage.PropertyIdList.Contains($exifOrientationTagId)) {
$propertyItem = $loadedImage.GetPropertyItem($exifOrientationTagId)
$val = [System.BitConverter]::ToUInt16($propertyItem.Value, 0)
[ExifOrientation]$val
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment