Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param ([string]$path,[string]$ext)
- function Refresh-Explorer
- {
- $code = @'
- [System.Runtime.InteropServices.DllImport("Shell32.dll")]
- public static extern Int32 SHParseDisplayName([MarshalAs(UnmanagedType.LPWStr)] String pszName, IntPtr pbc, out IntPtr ppidl, UInt32 sfgaoIn, out UInt32 psfgaoOut);
- [System.Runtime.InteropServices.DllImport("Shell32.dll")]
- private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
- [System.Runtime.InteropServices.DllImport("Shell32.dll")]
- private static extern int ILFree(IntPtr pidl);
- public static void Refresh(string path) {
- uint iAttribute;
- IntPtr pidl;
- SHParseDisplayName(path, IntPtr.Zero, out pidl, 0, out iAttribute);
- SHChangeNotify(0x00002000, 0x1000, IntPtr.Zero, IntPtr.Zero);
- ILFree(pidl);
- }
- '@
- Add-Type -MemberDefinition $code -Namespace MyWinAPI -Name Explorer
- [MyWinAPI.Explorer]::Refresh($path)
- }
- cls
- if([System.String]::IsNullOrEmpty($path))
- {
- Write-Host "Path cannot be empty."
- Write-Host "Example: .thumb_generate.ps1 -path ""C:"" -ext ""jpg"""
- return
- }
- if([System.String]::IsNullOrEmpty($path))
- {
- Write-Host "Extension cannot be empty."
- Write-Host "Example: .thumb_generate.ps1 -path ""C:"" -ext ""jpg"""
- return
- }
- $fileExtension = "*." + $ext
- Write-Host -ForegroundColor Green "---Thumbnail generation for Windows 7/8---"
- Write-Host -ForegroundColor Green "----PowerShell 3.0 & .Net 4.0 required----"
- Write-Host "Path: " $path
- Write-Host "Extension: " $fileExtension
- Write-Host
- if (Test-Path $path)
- {
- Write-Host "Path Exists, begin generation thumbnails"
- $images = [System.IO.Directory]::EnumerateFiles($path,$fileExtension,"AllDirectories")
- Foreach($image in $images)
- {
- try
- {
- $file = New-Object System.IO.FileInfo($image)
- Write-Host $file.FullName
- $fStream = $file.Open([System.IO.FileMode]::Open,[System.IO.FileAccess]::Read,[System.IO.FileShare]::None)
- $firstbyte = New-Object Byte[] 1
- $result = $fStream.Read($firstbyte,0,1)
- }
- catch
- {
- Write-Host -ForegroundColor Red "An error occured on file: " + $file.FullName
- }
- $fStream.Close();
- }
- Refresh-Explorer
- }
- else
- {
- "Path Doesn't Exist, Exiting..."
- }
- .thumb_generate.ps1 -path "C:PathToImages" -ext "jpg"
- public static void refreshThumbnail(string path)
- {
- try
- {
- uint iAttribute;
- IntPtr pidl;
- SHParseDisplayName(path, IntPtr.Zero, out pidl, 0, out iAttribute);
- SHChangeNotify(
- (uint)ShellChangeNotificationEvents.SHCNE_UPDATEITEM,
- (uint)ShellChangeNotificationFlags.SHCNF_FLUSH,
- pidl,
- IntPtr.Zero);
- ILFree(pidl);
- }
- catch { }
- }
- CoInitialize(NULL);
- IThumbnailCache *cache;
- HRESULT hr = CoCreateInstance(CLSID_LocalThumbnailCache, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&cache));
- if (SUCCEEDED(hr))
- {
- <loop over files>
- {
- cache->GetThumbnail(<shell item for file>, <required size>, WTS_EXTRACT, NULL, NULL, NULL);
- cache->Release();
- }
- }
- mkdir thumbjunk
- for f in *.jpg
- do convert $f -thumbnail 100x80 thumbjunk/$f.gif
- find * -prune -name '*.jpg'
- -exec convert '{}' -thumbnail 100x80 thumbjunk/'{}'.gif
- 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