Bildsortierung
Kurze Vorwarnung dass dies hier überwiegend KI-generiertes Zeug ist. Hat funktioniert, muss aber nicht erneut funktionieren. Es ist wichtig dass ihr in Grundzügen nachvollziehen könnt, was die Scripts tun, auch wenn sie generiert sind.
Das hier wird sicherlich irgendwann mal kombiniert in nem großen Script dass dann gewisse Auswahl zulässt.
Nach Bildauflösung
Skript sammelt Bilder die kleiner als festgelegte Auflösung sind in einem anderen Ordner und belässt die, die größer sind im Ordner.
param (
[string]$SourceFolder = "D:C:\bigger_downloads\wallhaven_dumps\nude"Path\to\SourceFolder",
[string]$DestinationFolder = "D:C:\bigger_downloads\wallhaven_dumps\nude-sd"Path\to\DestinationFolder",
[int]$MinWidth = 3840,
[int]$MinHeight = 2160
)
# Create the destination folder if it doesn't exist
if (-not (Test-Path $DestinationFolder)) {
New-Item -ItemType Directory -Path $DestinationFolder | Out-Null
}
# Get all image files in the source folder and its subfolders
$images = Get-ChildItem -Path $SourceFolder -Filter "*.jpg" -File -Recurse
$totalImages = $images.Count
$processedImages = 0
# Process each image file
foreach ($image in $images) {
Write-Host "Processing $($image.FullName)"
# Use .NET classes to read image dimensions
$imageStream = New-Object System.IO.FileStream($image.FullName, [System.IO.FileMode]::Open)
$imageBitmap = New-Object System.Drawing.Bitmap($imageStream)
$width = $imageBitmap.Width
$height = $imageBitmap.Height
$imageStream.Close()
# Check if the image is smaller than the specified dimensions
if ($width -lt $MinWidth -or $height -lt $MinHeight) {
$destinationPath = Join-Path -Path $DestinationFolder -ChildPath $image.Name
Write-Host "Moving $($image.FullName) to $destinationPath"
Move-Item -Path $image.FullName -Destination $destinationPath
}
$processedImages++
$progress = [math]::Round(($processedImages / $totalImages) * 100, 2)
Write-Progress -Activity "Moving images" -Status "Progress: $progress%" -PercentComplete $progress
}
Write-Progress -Activity "Moving images" -Status "Progress: 100%" -PercentComplete 100
Write-Host "Image move complete!"
Dedup
(falls Copy statt Move im Script vorab gemacht wurde)
Das Ding tut noch nicht das was ich will, womöglich komme ich selbst durcheinander mit Source und Destination. Ich setz also unten noch mal anders an.
param (
# wo soll gelöscht werden?
[string]$SourceFolder = "C:\Path\to\SourceFolder",
# wo liegen die files mit denen Verglichen werden soll?
[string]$DestinationFolder = "C:\Path\to\DestinationFolder",
# wird eigentlich nicht gebraucht, ist nur aus dem Kontext der vorherigen Scripts entstanden
[int]$MinWidth = 3840,
[int]$MinHeight = 2160
)
# Get all image files in the destination folder
$destinationImages = Get-ChildItem -Path $DestinationFolder -Filter "*.jpg" -File
# Process each image file in the destination folder
foreach ($destinationImage in $destinationImages) {
Write-Host "Processing $($destinationImage.FullName)"
# Construct the source file path based on the destination file name
$sourceFilePath = Join-Path -Path $SourceFolder -ChildPath $destinationImage.Name
# Check if the corresponding file exists in the source folder
if (Test-Path $sourceFilePath) {
Write-Host "Deleting $($sourceFilePath)"
Remove-Item -Path $sourceFilePath -Force
}
}
Write-Host "Duplicate removal complete!"
Die Abwesenheit von Bildern >4K-Auflösung nachvollziehen
$SourceFolder = "C:\Path\to\SourceFolder"
$MinWidth = 3840
$MinHeight = 2160
# Get all image files in the source folder and its subfolders
$images = Get-ChildItem -Path $SourceFolder -Filter "*.jpg" -File -Recurse
$totalImages = $images.Count
$processedImages = 0
# Process each image file
foreach ($image in $images) {
# Use .NET classes to read image dimensions
$imageStream = New-Object System.IO.FileStream($image.FullName, [System.IO.FileMode]::Open)
$imageBitmap = New-Object System.Drawing.Bitmap($imageStream)
$width = $imageBitmap.Width
$height = $imageBitmap.Height
$imageStream.Close()
# Check if the image is larger than the specified dimensions
if ($width -ge $MinWidth -and $height -ge $MinHeight) {
Write-Host "Found large image: $($image.FullName)"
}
$processedImages++
$progress = [math]::Round(($processedImages / $totalImages) * 100, 2)
Write-Progress -Activity "Checking image sizes" -Status "Progress: $progress%" -PercentComplete $progress
}
Write-Progress -Activity "Checking image sizes" -Status "Progress: 100%" -PercentComplete 100
Write-Host "Image size check complete!"
Alle Bilder > 4K löschen
$SourceFolder = "C:\Path\to\SourceFolder"
$MinWidth = 3840
$MinHeight = 2160
# Get all image files in the source folder and its subfolders
$images = Get-ChildItem -Path $SourceFolder -Filter "*.jpg" -File -Recurse
$totalImages = $images.Count
$processedImages = 0
# Process each image file
foreach ($image in $images) {
# Use .NET classes to read image dimensions
$imageStream = New-Object System.IO.FileStream($image.FullName, [System.IO.FileMode]::Open)
$imageBitmap = New-Object System.Drawing.Bitmap($imageStream)
$width = $imageBitmap.Width
$height = $imageBitmap.Height
$imageStream.Close()
# Check if the image is larger than the specified dimensions
if ($width -ge $MinWidth -and $height -ge $MinHeight) {
Write-Host "Deleting large image: $($image.FullName)"
Remove-Item -Path $image.FullName -Force
}
$processedImages++
$progress = [math]::Round(($processedImages / $totalImages) * 100, 2)
Write-Progress -Activity "Checking and deleting large images" -Status "Progress: $progress%" -PercentComplete $progress
}
Write-Progress -Activity "Checking and deleting large images" -Status "Progress: 100%" -PercentComplete 100
Write-Host "Image size check and deletion complete!"