2023-02-26 21:09:46 +01:00
|
|
|
|
<#
|
|
|
|
|
.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.
|
2023-02-28 22:13:31 +01:00
|
|
|
|
.PARAMETER ImageFile
|
|
|
|
|
Specifies the path to the image file
|
2023-02-26 21:09:46 +01:00
|
|
|
|
.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
|
|
|
|
|
#>
|
|
|
|
|
|
2023-02-28 22:13:31 +01:00
|
|
|
|
param([string]$ImageFile = "", [string]$TargetDir = "", [int]$ImageWidth = 1920, [int]$ImageHeight = 1393)
|
2023-02-26 21:09:46 +01:00
|
|
|
|
|
|
|
|
|
try {
|
2023-02-28 22:13:31 +01:00
|
|
|
|
if ($ImageFile -eq "") { $ImageFile = Read-Host "Enter file path to image file" }
|
2023-02-26 21:09:46 +01:00
|
|
|
|
if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" }
|
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
|
|
2023-02-28 22:13:31 +01:00
|
|
|
|
"⏳ (1/300) Checking image file..."
|
|
|
|
|
if (!(Test-Path "$ImageFile" -pathType leaf)) { throw "Can't access image file: $ImageFile" }
|
|
|
|
|
$Basename = (Get-Item "$ImageFile").Basename
|
2023-02-26 21:09:46 +01:00
|
|
|
|
|
2023-02-28 22:13:31 +01:00
|
|
|
|
"⏳ (2/300) Searching for ImageMagick 6..."
|
2023-02-26 21:09:46 +01:00
|
|
|
|
& convert-im6 --version
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'convert-im6' - make sure ImageMagick 6 is installed and available" }
|
|
|
|
|
|
2023-02-28 22:13:31 +01:00
|
|
|
|
[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++) {
|
2023-02-26 21:09:46 +01:00
|
|
|
|
$TargetFile = "$TargetDir/$($Basename)_$($i).jpg"
|
2023-02-28 22:13:31 +01:00
|
|
|
|
"⏳ ($i/$Frames) Copying to $TargetFile..."
|
|
|
|
|
& convert-im6 -stroke black -strokewidth 9 -fill white -draw "circle $centerX,$centerY $x,$centerY" "$ImageFile" "$TargetFile"
|
|
|
|
|
$x += $increment
|
2023-02-26 21:09:46 +01:00
|
|
|
|
}
|
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2023-02-28 22:13:31 +01:00
|
|
|
|
"✅ copied $ImageFile to $Frames frames in 📂$TargetDir in $Elapsed sec."
|
2023-02-26 21:09:46 +01:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|