tedbeer

detectChanges.ps1

Nov 8th, 2013
548
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. # Runs ImageMagick tool to find changed images
  3. # reference folder - folder with reference images
  4. # diff folder - folder where diff images are generated
  5. #
  6. # USAGE:
  7. #       powershell -File detectChanges.ps1 [-magick PathToImageMagick] [-diff PathToImageDiffFolder] [-reference PathToReferenceFolder]
  8. #
  9. #       powershell -File detectChanges.ps1
  10. #
  11. # or you can open and run this script from Windows PowerShell ISE
  12. #
  13. # requirement:
  14. #   - powershell
  15. #   - running powershell scripts is allowed:
  16. #     Set-ExecutionPolicy RemoteSigned (or Unrestricted)
  17. #
  18. #     in Windows Vista, Win7 and above you can change the setting
  19. #     only by running powershell with administrative rights
  20. #
  21. #     you have to change both 32 and 64 bit settings because they are separate, details:
  22. #     http://blog.unixwiz.net/2010/05/powershell-surprise-in-windows-7.html
  23. #
  24. #
  25. $magickFolder="D:/win_/ImageMagick-6.7.2-8/"
  26. $referenceFolder = "./reference/"
  27. $diffFolder = "./diff/"
  28. $imgMask = "./shots/*.png"
  29. $copy2reference = $false #$true #if reference file does not exist - copy tested file
  30.  
  31. #------------------ read command line
  32. $option = ""
  33. foreach ($nm in $args) {
  34.     switch ($nm) {
  35.         "-magick" { # folder with ImageMagick
  36.             $option = "magickFolder"
  37.         }
  38.         "-diff" { # folder to store image difference files
  39.             $option = "diffFolder"
  40.         }
  41.         "-reference" { #folder with reference images
  42.             $option = "referenceFolder"
  43.         }
  44.         "-copyReference" { #copy file to reference folder if necessary
  45.             $option = "copyReference"
  46.         }
  47.         default { #image mask to process
  48.             switch ($option) {
  49.                 "copyReference" {
  50.                     $copy2reference = $nm -eq "true"
  51.                 }
  52.                 "magickFolder" {
  53.                     $magickFolder = $nm
  54.                     if (!$magickFolder.EndsWith('/')) {$magickFolder += '/'}
  55.                 }
  56.                 "referenceFolder" {
  57.                     $referenceFolder = $nm
  58.                     if (!$referenceFolder.EndsWith('/')) {$referenceFolder += '/'}
  59.                 }
  60.                 "diffFolder" {
  61.                     $diffFolder = $nm
  62.                     if (!$diffFolder.EndsWith('/')) {$diffFolder += '/'}
  63.                 }
  64.                 default {
  65.                     $imgMask = $nm
  66.                 }
  67.             }
  68.             $option = ""
  69.         }
  70.     }
  71. }
  72.  
  73. #Clean diff folder
  74. $diffFiles = $diffFolder + "*.png"
  75. Remove-Item $diffFiles
  76.  
  77. foreach ($fl in get-childitem $imgMask) {
  78.     $in = $referenceFolder + $fl.name
  79.     if (Test-Path $in) { #file exists
  80.         Write-Host $fl.FullName
  81.         $diff = $diffFolder + "diff-" + $fl.name
  82.         $cmd = $magickFolder + "compare.exe"
  83.  
  84.         #redirect STDERR to STDIN
  85.         $res = & $cmd -metric AE $fl.FullName $in $diff 2>&1
  86.         if ($res.Exception.Message -eq 0) { #OK
  87.             #Write-Host '--------- OK---- ' $fl.name
  88.             Remove-Item $diff
  89.         } else { #FAIL
  90.             #Write-Host '============= FAIL === ' $fl.name
  91.         }
  92.     } else { #reference file doesn't exist
  93.         Write-Host $fl.name " - reference file doesn't exist"
  94.         if ($copy2reference) {
  95.             Write-Host "--- Copy " $fl.name " as the reference"
  96.             Copy-Item $fl $in
  97.         }
  98.     }
  99. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×