mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-06 02:21:32 +01:00
Update copy-image-blurred.ps1 and copy-image-pixelated.ps1
This commit is contained in:
parent
1e8de9a0c7
commit
4e215f4cd3
@ -16,28 +16,28 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$ImageFile = "", [string]$TargetDir = "", [int]$ImageWidth = 1920, [int]$ImageHeight = 1393)
|
param([string]$ImageFile = "", [string]$TargetDir = "", [int]$ImageWidth = 1920, [int]$ImageHeight = 1393, [int]$Frames = 300)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($ImageFile -eq "") { $ImageFile = Read-Host "Enter file path to image file" }
|
if ($ImageFile -eq "") { $ImageFile = Read-Host "Enter file path to image file" }
|
||||||
if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" }
|
if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" }
|
||||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
"⏳ (1/300) Checking image file..."
|
"⏳ (1/$Frames) Checking image file..."
|
||||||
if (!(Test-Path "$ImageFile" -pathType leaf)) { throw "Can't access image file: $ImageFile" }
|
if (!(Test-Path "$ImageFile" -pathType leaf)) { throw "Can't access image file: $ImageFile" }
|
||||||
$Basename = (Get-Item "$ImageFile").Basename
|
$Basename = (Get-Item "$ImageFile").Basename
|
||||||
|
|
||||||
"⏳ (2/300) Searching for ImageMagick 6..."
|
"⏳ (2/$Frames) Searching for ImageMagick 6..."
|
||||||
& convert-im6 --version
|
& convert-im6 --version
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'convert-im6' - make sure ImageMagick 6 is installed and available" }
|
if ($lastExitCode -ne "0") { throw "Can't execute 'convert-im6' - make sure ImageMagick 6 is installed and available" }
|
||||||
|
|
||||||
[int]$centerX = $ImageWidth / 2
|
[int]$centerX = $ImageWidth / 2
|
||||||
[int]$centerY = $ImageHeight / 2
|
[int]$centerY = $ImageHeight / 2
|
||||||
[int]$Frames = 300
|
|
||||||
[int]$x = 0
|
[int]$x = 0
|
||||||
[float]$increment = $centerX / $Frames
|
[float]$increment = $centerX / $Frames
|
||||||
for ($i = 0; $i -lt $Frames; $i++) {
|
for ($i = 0; $i -lt $Frames; $i++) {
|
||||||
$TargetFile = "$TargetDir/$($Basename)_$($i).jpg"
|
$FrameNo = '{0:d4}' -f $i
|
||||||
|
$TargetFile = "$TargetDir/frame_$($FrameNo).jpg"
|
||||||
"⏳ ($i/$Frames) Copying to $TargetFile..."
|
"⏳ ($i/$Frames) Copying to $TargetFile..."
|
||||||
& convert-im6 -stroke black -strokewidth 9 -fill white -draw "circle $centerX,$centerY $x,$centerY" "$ImageFile" "$TargetFile"
|
& convert-im6 -stroke black -strokewidth 9 -fill white -draw "circle $centerX,$centerY $x,$centerY" "$ImageFile" "$TargetFile"
|
||||||
$x += $increment
|
$x += $increment
|
||||||
|
@ -33,7 +33,8 @@ try {
|
|||||||
|
|
||||||
$Factor = 0.001
|
$Factor = 0.001
|
||||||
for ($i = 0; $i -lt 297; $i++) {
|
for ($i = 0; $i -lt 297; $i++) {
|
||||||
$TargetFile = "$TargetDir/$($Basename)_$($i).jpg"
|
$FrameNo = '{0:d4}' -f $i
|
||||||
|
$TargetFile = "$TargetDir/frame_$($FrameNo).jpg"
|
||||||
"⏳ ($($i + 3)/300) Copying to $TargetFile with pixelation factor $Factor..."
|
"⏳ ($($i + 3)/300) Copying to $TargetFile with pixelation factor $Factor..."
|
||||||
$Coeff1 = 100.0 * $Factor
|
$Coeff1 = 100.0 * $Factor
|
||||||
$Coeff2 = 100.0 / $Factor
|
$Coeff2 = 100.0 / $Factor
|
||||||
@ -42,7 +43,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
"✅ copied $SourceFile to a series of 300 pixelated images in 📂$TargetDir in $Elapsed sec."
|
"✅ copied $SourceFile to a series of 300 pixelated frames in 📂$TargetDir in $Elapsed sec."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user