// FCLT#64524 WScript.Echo("// scriptfile: FCLT#64524.js"); WScript.Echo("// Herstelscript voor thumbnail foto's. Voegt ontbrekende thumbnails toe."); WScript.Echo("// Parameters: Pad vanaf waar gezocht moet worden."); WScript.Echo("// Naam van map waarin de originele afbeeldingen staan."); WScript.Echo("// Gestart op " + new Date()); // Voorbeeld: // cscript -e:javascript fclt#64524.js w:\branch20202\CUST\MDUX\photos\INS INSDEEL // // Beginnend in pad "w:\branch20202\CUST\MDUX\photos\INS" wordt recursief gezocht naar de map "INSDEEL" // waarin de originele afbeeldingen staan. // In de map "w:\branch20202\CUST\MDUX\photos\INS\...\...\INSDEEL\thumb" wordt gekeken of er van de // originele afbeelding een thumbnail bestaat. Zo niet dan wordt deze aangemaakt. Bestaat de "thumb"-map // niet dan wordt deze ook aangemaakt. if (WScript.Arguments.length < 2) { WScript.Echo("Onvoldoende parameters meegegeven."); } else { var StartPath = WScript.Arguments(0); var OrgMap = WScript.Arguments(1); WScript.Echo("// Start in: " + StartPath); WScript.Echo("// Afbeeldingen in map: " + OrgMap); WScript.Echo("//"); var fso = new ActiveXObject("Scripting.FileSystemObject"); if (fso.FolderExists(StartPath)) { var count_picture = 0; var count_resize = 0; var StartFolder = fso.GetFolder(StartPath); LoopFolder(StartFolder, OrgMap); WScript.Echo("//"); WScript.Echo("// Aantal afbeeldingen gevonden: " + count_picture); WScript.Echo("// Aantal afbeeldingen verkleind: " + count_resize); } else WScript.Echo("Onbekend pad: " + StartPath); } WScript.Echo("// Klaar op " + new Date()); WScript.Quit(0); function LoopFolder(thisfolder, map) { var enumFolder = new Enumerator(thisfolder.SubFolders); for (; !enumFolder.atEnd(); enumFolder.moveNext()) { var nextfolder = enumFolder.item(); if (nextfolder.name == map) ResizeFolder(nextfolder); else LoopFolder(nextfolder, map); } } function ResizeFolder(OrgPath) { WScript.Echo(OrgPath); var message = ""; var enumFile = new Enumerator(OrgPath.Files); for (; !enumFile.atEnd(); enumFile.moveNext()) { var thisfile = enumFile.item(); var f = fso.GetFile(thisfile); if (f.Name.match(/\.(png|jpg|jpeg)$/i)) { count_picture ++; var ThumbPath = OrgPath + "/thumb/"; if (!fso.FolderExists(ThumbPath)) fso.CreateFolder(ThumbPath); if (!fso.FileExists(ThumbPath + f.Name)) resizeImage( {OrgPath: OrgPath, Name: f.Name} ); } } } function resizeImage(pic) { WScript.Echo("Resizing: " + pic.Name); //return; var message = ""; var oIMG = new ActiveXObject("SLNKDWF.ImageConvert"); try { oIMG.Open(pic.OrgPath + "/" + pic.Name); } catch(e) { message = "Kan afbeelding niet vinden " + pic.OrgPath + "/" + pic.Name; } if (!message) { try { var maxThumbW = 60; var maxThumbH = 80; if (oIMG.Width / oIMG.Height > maxThumbW / maxThumbH) { oIMG.Height = oIMG.Height / oIMG.Width * maxThumbW; oIMG.Width = maxThumbW; } else { oIMG.Width = oIMG.Width / oIMG.Height * maxThumbH; oIMG.Height = maxThumbH; } oIMG.SaveAs(pic.OrgPath + "/thumb/" + pic.Name); //message = "Thumbnail created"; count_resize ++; } catch (e) { message = "thumbnail_error: " + e.description; fso.DeleteFile(pic.OrgPath + "/thumb/" + pic.Name, true); } } if (message) WScript.Echo(message); }