PowerShell/docs/convert-image2blurred-frames.md

74 lines
2.5 KiB
Markdown
Raw Normal View History

2024-01-25 13:37:12 +01:00
Script: *convert-image2blurred-frames.ps1*
========================
2023-05-26 12:20:18 +02:00
convert-image2blurred-frames.ps1 [[-ImageFile] <string>] [[-TargetDir] <string>] [[-ImageWidth] <int>] [[-ImageHeight] <int>] [[-Frames] <int>]
2023-07-29 10:04:38 +02:00
Parameters
----------
2023-05-26 12:20:18 +02:00
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2023-05-26 12:20:18 +02:00
```powershell
<#
.SYNOPSIS
Converts an image into blurred frames
.DESCRIPTION
This PowerShell script converts a single image file into a series of blurred frames 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> ./convert-image2blurred-frames 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, [int]$Frames = 600)
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/$Frames) Checking image file..."
if (!(Test-Path "$ImageFile" -pathType leaf)) { throw "Can't access image file: $ImageFile" }
$Basename = (Get-Item "$ImageFile").Basename
"⏳ (2/$Frames) 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]$x = 0
[float]$increment = $centerX / $Frames
for ($i = 0; $i -lt $Frames; $i++) {
$FrameNo = '{0:d4}' -f $i
$TargetFile = "$TargetDir/frame_$($FrameNo).jpg"
"⏳ ($i/$Frames) Converting with r=$($centerX - $x) 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
"✅ converted image $ImageFile to $Frames blurred frames in 📂$TargetDir in $Elapsed sec."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
2024-08-15 09:51:46 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of convert-image2blurred-frames.ps1 as of 08/15/2024 09:50:47)*