diff --git a/Scripts/copy-image-blurred.ps1 b/Scripts/copy-image-blurred.ps1 new file mode 100755 index 00000000..31d1823e --- /dev/null +++ b/Scripts/copy-image-blurred.ps1 @@ -0,0 +1,57 @@ +<# +.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 SourceFile + Specifies the path to the image source 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]$SourceFile = "", [string]$TargetDir = "") + +try { + if ($SourceFile -eq "") { $SourceFile = Read-Host "Enter file path to source image file" } + if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" } + $StopWatch = [system.diagnostics.stopwatch]::startNew() + + "⏳ (1/300) Checking source image file..." + if (!(Test-Path "$SourceFile" -pathType leaf)) { throw "Can't access source image file: $SourceFile" } + $Basename = (Get-Item "$SourceFile").Basename + + "⏳ (2/300) Searching for ImageMagick 6 executable..." + & convert-im6 --version + if ($lastExitCode -ne "0") { throw "Can't execute 'convert-im6' - make sure ImageMagick 6 is installed and available" } + + [int]$ImageWidth = 3509 + [int]$ImageHeight = 2481 + [int]$radius = 10 + [float]$heading = 0.0 + [float]$distance = 0.0 + for ($i = 297; $i -gt 0; $i--) { + $TargetFile = "$TargetDir/$($Basename)_$($i).jpg" + "⏳ ($(300 - $i)/300) Copying to $TargetFile..." + [int]$x = $ImageWidth / 2 + [math]::cos($heading) * $distance + [int]$y = $ImageHeight / 2 + [math]::sin($heading) * $distance + & convert-im6 -fill black -draw "circle $x,$y $($x+$radius),$y" "$SourceFile" "$TargetFile" + $distance += 5 + $heading += 0.3 + $radius += 2 + $SourceFile = $TargetFile + } + + [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds + "✅ copied to a series of 300 blurred images in 📂$TargetDir in $Elapsed sec." + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +} diff --git a/Scripts/copy-image-pixelated.ps1 b/Scripts/copy-image-pixelated.ps1 index 9e073666..9cfdf5a5 100755 --- a/Scripts/copy-image-pixelated.ps1 +++ b/Scripts/copy-image-pixelated.ps1 @@ -3,6 +3,7 @@ Copy a single image into a series of pixelated images .DESCRIPTION This PowerShell script copies a single image file into a series of pixelated images in a target dir. + Requires ImageMagick 6. .PARAMETER SourceFile Specifies the path to the image source file .PARAMTER TargetDir @@ -22,19 +23,26 @@ try { if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" } $StopWatch = [system.diagnostics.stopwatch]::startNew() + "⏳ (1/300) Checking source image file..." + if (!(Test-Path "$SourceFile" -pathType leaf)) { throw "Can't access source image file: $SourceFile" } $Basename = (Get-Item "$SourceFile").Basename + + "⏳ (2/300) Searching for ImageMagick 6 executable..." + & convert-im6 --version + if ($lastExitCode -ne "0") { throw "Can't execute 'convert-im6' - make sure ImageMagick 6 is installed and available" } + $Factor = 0.001 - for ($i = 0; $i -lt 300; $i++) { + for ($i = 0; $i -lt 297; $i++) { $TargetFile = "$TargetDir/$($Basename)_$($i).jpg" - Write-Host "⏳ Copying $SourceFile to $TargetFile with pixelation factor $Factor..." + "⏳ ($($i + 3)/300) Copying to $TargetFile with pixelation factor $Factor..." $Coeff1 = 100.0 * $Factor $Coeff2 = 100.0 / $Factor - & convert -scale $Coeff1% -scale $Coeff2% "$SourceFile" "$TargetFile" + & convert-im6 -scale $Coeff1% -scale $Coeff2% "$SourceFile" "$TargetFile" $Factor += 0.0005 } [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 images in 📂$TargetDir in $Elapsed sec." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"