Skip to content

Instantly share code, notes, and snippets.

@zplume
Created August 8, 2020 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zplume/884416cb7f9bdbbb99fc67e965537829 to your computer and use it in GitHub Desktop.
Save zplume/884416cb7f9bdbbb99fc67e965537829 to your computer and use it in GitHub Desktop.
$imagePath = "$home\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*"
$destinationPath = "$home\OneDrive\Pictures\Lock screen"
Add-Type -AssemblyName System.Drawing
# get images from lock screen folder
$items = Get-ChildItem -Path $imagePath
foreach($item in $items) {
$fileName = $item.Name
# skip small images/icons
if($item.Length -lt 100000) {
Write-Host " Skipped " -b Red -f Black -NoNewline
Write-Host -f White " $($fileName).jpg"
continue
}
# get image dimensions
$image = New-Object System.Drawing.Bitmap $item.FullName
$imageWidth = $image.Width
$imageHeight = $image.Height
$image.Dispose() # prevent file lock
# separate images into Landscape/Portrait destination sub-folders
# note: the script assumes these folders already exist
if($imageWidth -gt $imageHeight) {
$newPath = "$destinationPath\Landscape\$($fileName).jpg"
}
else {
$newPath = "$destinationPath\Portrait\$($fileName).jpg"
}
# only copy files that haven't
# already been copied
if(!(Test-Path $newPath)) {
Copy-Item -Path $item.FullName -Destination $newPath
Write-Host -b Green -f Black " Copied " -NoNewline
}
else {
Write-Host -b Yellow -f Black " Exists " -NoNewline
}
Write-Host -f White " $($fileName).jpg"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment