{"id":54,"date":"2007-08-04T12:06:45","date_gmt":"2007-08-04T10:06:45","guid":{"rendered":"http:\/\/unckel.com\/blog\/?p=54"},"modified":"2019-12-07T22:21:25","modified_gmt":"2019-12-07T21:21:25","slug":"photoshop-script-alle-bilder-in-einem-ordner-verkleinern-rand-entfernen-und-speichern","status":"publish","type":"post","link":"https:\/\/unckel.de\/blog\/photoshop-script-alle-bilder-in-einem-ordner-verkleinern-rand-entfernen-und-speichern\/","title":{"rendered":"Photoshop Script: Alle Bilder in einem Ordner verkleinern, Rand entfernen und speichern"},"content":{"rendered":"<p>Skaliert alle Bilder aus einem Ordner auf die gegebene maximal Breite\/H\u00f6he und speichert diese wieder ab. Zus\u00e4tzlich kann ein Rand entfernt und der Dateiname angepasst werden.<\/p>\n<pre>\/\/###################################################################################\n\/\/\n\/\/ Crop image by dialog\n\/\/ Resize images to max 500px depends of witgh\/height and save as JPG\n\/\/ Photoshop Script (CS2, tested on PC) \n\/\/\n\/\/###################################################################################\n\n\/\/ main settings\nvar picSourcePath = \"C:\\\\Test\\\\Original\\\\\";\nvar picTargetPath = \"C:\\\\Test\\\\JPG\\\\\";\nvar maxSize = 500; \/\/ max width and height\n\n\/\/###################################################################################\n\n\/\/ save settings and customize environment\nvar startRulerUnits = app.preferences.rulerUnits;\nvar startTypeUnits = app.preferences.typeUnits;\nvar startDisplayDialogs = app.displayDialogs;\napp.preferences.rulerUnits = Units.PIXELS;\napp.preferences.typeUnits = TypeUnits.PIXELS;\napp.displayDialogs = DialogModes.NO;\n\/\/var doc = app.activeDocument;\n\nvar picFolder = Folder(picSourcePath);\nvar fileList = picFolder.getFiles();\n\nif (picSourcePath != null &amp;&amp; picTargetPath != null) {\n\n\tfor (var i=0; i&lt;fileList.length; i++) {\n\n\t\tif (fileList[i] instanceof File) {\n\t\t\topen(fileList[i]);\n\n\t\t\tvar newFileName = fileList[i].name;\n\t\t\tapp.activeDocument.changeMode(ChangeMode.RGB);\n\n\t\t\tif (app.activeDocument.width &gt; maxSize || app.activeDocument.height &gt; maxSize) { \n\n\t\t\t\t\/\/ remove surrounding\n\t\t\t\tvar cropSize = prompt('Crop from Border (px).', '');\n\n\t\t\t\tif (cropSize != '' &amp;&amp; cropSize &gt; 0 &amp;&amp; \n\t\t\t\t\tcropSize &lt; app.activeDocument.width &amp;&amp; \n\t\t\t\t\tcropSize &lt; app.activeDocument.height) { \n\t\t\t\t\t\tcropWidthFromBorder(cropSize);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\/\/ resize\n\t\t\t\tresize(maxSize);\t\t\n\n\t\t\t\t\/\/if (confirm('Sharpen?')) {\t\t\t\t\t\t\n\t\t\t\t\/\/\tapp.activeDocument.activeLayer.applySharpen();\n\t\t\t\t\/\/}\n\t\t\t\t\n\t\t\t\t\/\/if (confirm('Save and Close?')) {\t\t\t\t\t\t\n\t\t\t\t\tsaveWebJpg(newFileName.substring(0, newFileName.length-4) + \".jpg\", picTargetPath, 75);\n\t\t\t\t\t\/\/app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);\n\t\t\t\t\/\/}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t\/\/ if pictures already 500px or smaller, then only rename\n\t\t\t\tfileList[i].rename(picTargetPath + newFileName.substring(0, newFileName.length-4) + \".jpg\");\n\t\t\t}\n\t\t\t\n\t\t\t\/\/ ... and close at all events\n\t\t\tapp.activeDocument.close(SaveOptions.DONOTSAVECHANGES);\n\t\t}\n\t}\n}\n\n\n\/\/ restore settings\napp.preferences.rulerUnits = startRulerUnits;\napp.preferences.typeUnits = startTypeUnits;\napp.displayDialogs = startDisplayDialogs;\n\nalert(\"Done!\");\n\n\/\/ Funktion um Dokument als Jpeg zu speichern (Fuer Web speichern...)\n\/\/ Parameter: Dateiname, Pfad mit abschliessendem '\\'!, Qualitaet 1-100\n\/\/ Beispielaufruf: saveWebJpg(\"test.jpg\", \"c:\\\\bilder\\\\\", 75);\nfunction saveWebJpg(jpgName, filePath, jpgQuality ) {\n var saveFile = new File(filePath + jpgName);\n var webJpgOptions = new ExportOptionsSaveForWeb();\n webJpgOptions.format = SaveDocumentType.JPEG;\n webJpgOptions.optimized = true;\n webJpgOptions.quality = jpgQuality;\n activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, webJpgOptions);\n File = null; ExportOptionsSaveForWeb = null;\n}\n\n\/\/ http:\/\/www.chadwickwood.com\/2008\/11\/conditional-image-resizing-with-photoshop-and-javascript\nfunction resize(size)\n{\n  if(app.activeDocument.width &gt; app.activeDocument.height)\n    app.activeDocument.resizeImage(size, (size * app.activeDocument.height\/app.activeDocument.width),null, ResampleMethod.BICUBIC);\n  else\n    app.activeDocument.resizeImage((size * app.activeDocument.width\/app.activeDocument.height), size, null, ResampleMethod.BICUBIC);\n} \n\nfunction cropWidthFromBorder(cropWidth) { \n\tapp.activeDocument.crop(Array(\n\t\tcropWidth,\n\t\tcropWidth,\n\t\tapp.activeDocument.width - cropWidth,\n\t\tapp.activeDocument.height - cropWidth));\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Skaliert alle Bilder aus einem Ordner auf die gegebene maximal Breite\/H\u00f6he und speichert diese wieder ab. Zus\u00e4tzlich kann ein Rand entfernt und der Dateiname angepasst werden. \/\/################################################################################### \/\/ \/\/ Crop image by dialog \/\/ Resize images to max 500px depends of witgh\/height and save as JPG \/\/ Photoshop Script (CS2, tested on PC) \/\/ \/\/################################################################################### [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-adobe-photoshop"],"_links":{"self":[{"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":1,"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":819,"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/819"}],"wp:attachment":[{"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unckel.de\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}