Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. param ([string]$path,[string]$ext)
  2. function Refresh-Explorer
  3. {
  4. $code = @'
  5. [System.Runtime.InteropServices.DllImport("Shell32.dll")]
  6. public static extern Int32 SHParseDisplayName([MarshalAs(UnmanagedType.LPWStr)] String pszName, IntPtr pbc, out IntPtr ppidl, UInt32 sfgaoIn, out UInt32 psfgaoOut);
  7.  
  8. [System.Runtime.InteropServices.DllImport("Shell32.dll")]
  9. private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
  10.  
  11. [System.Runtime.InteropServices.DllImport("Shell32.dll")]
  12. private static extern int ILFree(IntPtr pidl);
  13.  
  14. public static void Refresh(string path) {
  15. uint iAttribute;
  16. IntPtr pidl;
  17. SHParseDisplayName(path, IntPtr.Zero, out pidl, 0, out iAttribute);
  18. SHChangeNotify(0x00002000, 0x1000, IntPtr.Zero, IntPtr.Zero);
  19. ILFree(pidl);
  20. }
  21. '@
  22.  
  23. Add-Type -MemberDefinition $code -Namespace MyWinAPI -Name Explorer
  24. [MyWinAPI.Explorer]::Refresh($path)
  25. }
  26.  
  27. cls
  28. if([System.String]::IsNullOrEmpty($path))
  29. {
  30. Write-Host "Path cannot be empty."
  31. Write-Host "Example: .thumb_generate.ps1 -path ""C:"" -ext ""jpg"""
  32. return
  33. }
  34. if([System.String]::IsNullOrEmpty($path))
  35. {
  36. Write-Host "Extension cannot be empty."
  37. Write-Host "Example: .thumb_generate.ps1 -path ""C:"" -ext ""jpg"""
  38. return
  39. }
  40.  
  41. $fileExtension = "*." + $ext
  42. Write-Host -ForegroundColor Green "---Thumbnail generation for Windows 7/8---"
  43. Write-Host -ForegroundColor Green "----PowerShell 3.0 & .Net 4.0 required----"
  44. Write-Host "Path: " $path
  45. Write-Host "Extension: " $fileExtension
  46. Write-Host
  47. if (Test-Path $path)
  48. {
  49. Write-Host "Path Exists, begin generation thumbnails"
  50.  
  51. $images = [System.IO.Directory]::EnumerateFiles($path,$fileExtension,"AllDirectories")
  52. Foreach($image in $images)
  53. {
  54. try
  55. {
  56. $file = New-Object System.IO.FileInfo($image)
  57. Write-Host $file.FullName
  58. $fStream = $file.Open([System.IO.FileMode]::Open,[System.IO.FileAccess]::Read,[System.IO.FileShare]::None)
  59.  
  60. $firstbyte = New-Object Byte[] 1
  61. $result = $fStream.Read($firstbyte,0,1)
  62. }
  63. catch
  64. {
  65. Write-Host -ForegroundColor Red "An error occured on file: " + $file.FullName
  66. }
  67. $fStream.Close();
  68. }
  69. Refresh-Explorer
  70. }
  71. else
  72. {
  73. "Path Doesn't Exist, Exiting..."
  74. }
  75.  
  76. .thumb_generate.ps1 -path "C:PathToImages" -ext "jpg"
  77.  
  78. public static void refreshThumbnail(string path)
  79. {
  80. try
  81. {
  82. uint iAttribute;
  83. IntPtr pidl;
  84. SHParseDisplayName(path, IntPtr.Zero, out pidl, 0, out iAttribute);
  85. SHChangeNotify(
  86. (uint)ShellChangeNotificationEvents.SHCNE_UPDATEITEM,
  87. (uint)ShellChangeNotificationFlags.SHCNF_FLUSH,
  88. pidl,
  89. IntPtr.Zero);
  90. ILFree(pidl);
  91.  
  92. }
  93. catch { }
  94. }
  95.  
  96. CoInitialize(NULL);
  97.  
  98. IThumbnailCache *cache;
  99. HRESULT hr = CoCreateInstance(CLSID_LocalThumbnailCache, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&cache));
  100. if (SUCCEEDED(hr))
  101. {
  102. <loop over files>
  103. {
  104. cache->GetThumbnail(<shell item for file>, <required size>, WTS_EXTRACT, NULL, NULL, NULL);
  105. cache->Release();
  106. }
  107. }
  108.  
  109. mkdir thumbjunk
  110. for f in *.jpg
  111. do convert $f -thumbnail 100x80 thumbjunk/$f.gif
  112.  
  113. find * -prune -name '*.jpg'
  114. -exec convert '{}' -thumbnail 100x80 thumbjunk/'{}'.gif
  115.  
  116. ffmpeg -ss 00:01:00 -i testavi.avi -vf 'select=not(mod(n,1000)),scale=320:240,tile=2x3' testavi.png
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement