Advertisement
hl2guide

JPEG Optimizer 1.0A - PowerShell

Jan 6th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # JPEG Optimizer
  2. # Optimizes JPEGs in a folder using Google JPEG optimizer "Guetzli"
  3. # Version: 1.0A
  4.  
  5. $optimizerTool = 'C:\Users\Dean\Documents\Batch Scripts\Commands\guetzli-x64.exe'
  6.  
  7. $inputFolder = 'C:\webserver\htdocs\webman1\resources\jpg\avatars'
  8. $outputFolder = 'C:\webserver\htdocs\webman1\resources\jpg\avatars\converted'
  9.  
  10. # End Edits
  11.  
  12. if((Test-Path $optimizerTool) -ne $true)
  13. {
  14.     Write-Host 'Please check optimizerTool path is correct: '$optimizerTool -ForegroundColor Red
  15.     exit
  16. }
  17. if((Test-Path $inputFolder) -ne $true)
  18. {
  19.     Write-Host 'Please check inputFolder path is correct: '$inputFolder -ForegroundColor Red
  20.     exit
  21. }
  22. if((Test-Path $outputFolder) -ne $true)
  23. {
  24.     Write-Host 'Please check outputFolder path is correct: '$outputFolder -ForegroundColor Red
  25.     exit
  26. }
  27.  
  28. $jpegList = Get-ChildItem -Path $inputFolder -Filter '*.jpg'
  29. $numberOfJPEGs =  $jpegList | Measure-Object | ForEach-Object{$_.Count}
  30.  
  31. Write-Host 'Found'$numberOfJPEGs' images to optimize. Continue?' -ForegroundColor Cyan
  32.  
  33. pause
  34.  
  35. Write-Host 'Optimizing JPEG images using guetzli, please wait..' -ForegroundColor Yellow
  36.  
  37. foreach($file in $jpegList)
  38. {
  39.     #Write-Host 'Optimizing "'$file.Name.'", please wait..' -ForegroundColor Cyan
  40.     Write-Host "Optimizing $file, please wait.." -ForegroundColor Cyan
  41.     $output = '"'+$file.FullName+'" "'+$outputFolder+'\'+$file.Name+'"'
  42.     $arguments = '--quality 99 '+$output
  43.     # $arguments
  44.     $process = Start-Process $optimizerTool -ArgumentList $arguments -PassThru -Wait -NoNewWindow
  45.     $process.WaitForExit()
  46. }
  47.  
  48. Write-Host 'Optimized JPEG images using guetzli. Please check the output files in: '$outputFolder -ForegroundColor Green
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement