PowerShell/Scripts/copy-image-blurred.ps1
2023-02-28 22:13:31 +01:00

52 lines
1.8 KiB
PowerShell
Executable File

<#
.SYNOPSIS
Copy a single image into a series of blurred images
.DESCRIPTION
This PowerShell script copies a single image file into a series of blurred images in a target dir.
Requires ImageMagick 6.
.PARAMETER ImageFile
Specifies the path to the image file
.PARAMTER TargetDir
Specifies the path to the target folder
.EXAMPLE
PS> ./copy-image-blurred C:\photo.jpg C:\Temp
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$ImageFile = "", [string]$TargetDir = "", [int]$ImageWidth = 1920, [int]$ImageHeight = 1393)
try {
if ($ImageFile -eq "") { $ImageFile = Read-Host "Enter file path to image file" }
if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" }
$StopWatch = [system.diagnostics.stopwatch]::startNew()
"⏳ (1/300) Checking image file..."
if (!(Test-Path "$ImageFile" -pathType leaf)) { throw "Can't access image file: $ImageFile" }
$Basename = (Get-Item "$ImageFile").Basename
"⏳ (2/300) Searching for ImageMagick 6..."
& convert-im6 --version
if ($lastExitCode -ne "0") { throw "Can't execute 'convert-im6' - make sure ImageMagick 6 is installed and available" }
[int]$centerX = $ImageWidth / 2
[int]$centerY = $ImageHeight / 2
[int]$Frames = 300
[int]$x = 0
[float]$increment = $centerX / $Frames
for ($i = 0; $i -lt $Frames; $i++) {
$TargetFile = "$TargetDir/$($Basename)_$($i).jpg"
"⏳ ($i/$Frames) Copying to $TargetFile..."
& convert-im6 -stroke black -strokewidth 9 -fill white -draw "circle $centerX,$centerY $x,$centerY" "$ImageFile" "$TargetFile"
$x += $increment
}
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✅ copied $ImageFile to $Frames frames in 📂$TargetDir in $Elapsed sec."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}