Last active
February 20, 2023 19:15
-
-
Save michaellwest/edf8154f8fb4b8d2636390ba76707a48 to your computer and use it in GitHub Desktop.
Get the blob stream of a media item using Sitecore PowerShell Extensions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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