2023-02-26 21:09:46 +01:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2023-03-06 20:45:22 +01:00
|
|
|
|
Converts an image into blurred frames
|
2023-02-26 21:09:46 +01:00
|
|
|
|
.DESCRIPTION
|
2023-03-06 20:45:22 +01:00
|
|
|
|
This PowerShell script converts a single image file into a series of blurred frames in a target dir.
|
2023-02-26 21:09:46 +01:00
|
|
|
|
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
|
2023-03-06 20:45:22 +01:00
|
|
|
|
PS> ./convert-image2blurred-frames C:\photo.jpg C:\Temp
|
2023-02-26 21:09:46 +01:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
2023-03-06 21:29:00 +01:00
|
|
|
|
param([string]$ImageFile = "", [string]$TargetDir = "", [int]$ImageWidth = 1920, [int]$ImageHeight = 1393, [int]$Frames = 600)
|
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-03-03 12:34:42 +01:00
|
|
|
|
"⏳ (1/$Frames) Checking image file..."
|
2023-02-28 22:13:31 +01:00
|
|
|
|
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-03-03 12:34:42 +01:00
|
|
|
|
"⏳ (2/$Frames) 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]$x = 0
|
|
|
|
|
[float]$increment = $centerX / $Frames
|
|
|
|
|
for ($i = 0; $i -lt $Frames; $i++) {
|
2023-03-03 12:34:42 +01:00
|
|
|
|
$FrameNo = '{0:d4}' -f $i
|
|
|
|
|
$TargetFile = "$TargetDir/frame_$($FrameNo).jpg"
|
2023-03-06 21:29:00 +01:00
|
|
|
|
"⏳ ($i/$Frames) Converting with r=$($centerX - $x) to $TargetFile..."
|
2023-02-28 22:13:31 +01:00
|
|
|
|
& 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-03-06 21:29:00 +01:00
|
|
|
|
"✅ converted image $ImageFile to $Frames blurred 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
|
|
|
|
|
}
|