Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active February 20, 2023 19:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/edf8154f8fb4b8d2636390ba76707a48 to your computer and use it in GitHub Desktop.
Save michaellwest/edf8154f8fb4b8d2636390ba76707a48 to your computer and use it in GitHub Desktop.
Get the blob stream of a media item using Sitecore PowerShell Extensions.
$exifOrientationId = 0x112
if(!$items) {
$items = Get-ChildItem -Path "master:" -ID "{5D50B0FD-AB2B-4872-88E5-463D6E2B31F2}" -Recurse | Where-Object { $_.TemplateId -eq "{DAF085E8-602E-43A6-8299-038FF171349F}" }
}
$records = [System.Collections.ArrayList]@()
$processedCounter = 0
$totalCounter = $items.Count
foreach($item in $items) {
$processedCounter++
Write-Progress -Activity "Processing" -Status $item.Name -PercentComplete ($processedCounter * 100 / $totalCounter)
$mediaItem = [Sitecore.Data.Items.MediaItem]$item
$blobField = $mediaItem.InnerItem.Fields["blob"]
$blobStream = $blobField.GetBlobStream()
$image = [System.Drawing.Image]::FromStream($blobStream)
if($image.PropertyIdList.Contains($exifOrientationId)) {
$prop = $image.GetPropertyItem($exifOrientationId)
$rot = [System.BitConverter]::ToUInt16($prop.Value, 0)
if($rot -ne 0) {
$record = [PSCustomObject]@{
"ID" = $item.ID
"ItemPath" = $item.ItemPath
"RotateFlipType" = [Enum]::Parse([System.Drawing.RotateFlipType], $rot)
}
$records.Add($record) > $null
}
}
$image.Dispose()
$blobStream.Dispose()
}
$records | Show-ListView -Property ID,ItemPath,RotateFlipType
$item = Get-Item -Path "master:" -Id "{6AA5AA9F-071A-4808-91AC-709FAAFFB310}"
$mediaItem = [Sitecore.Data.Items.MediaItem]$item
$blobField = $mediaItem.InnerItem.Fields["blob"]
$blobField.GetBlobStream()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment