Photoshop 連續擷取圖片 - 進階版

  • 0

修改重點

  1. 讓裁切尺寸不限定在正方形,而是固定的幾種尺寸
  2. 記住前一個開啟檔案的名稱到剪貼簿,你可以快速命名

限制

  1. 它記住的是 PhotoShop 前一個分頁的名稱,可能不是來源圖檔
  2. 使用 batch 將檔名從 PhotoShop 引到剪貼簿,因此會看到命令提示視窗短時間跳出來
  3. Windows XP 使用者請下載 Clip.exe 放到 Windows 目錄底下

app.preferences.rulerUnits  = Units.PIXELS;
var w = app.activeDocument.width;
var h = app.activeDocument.height;
var white = new SolidColor(); 
white.rgb.hexValue = "FFFFFF";
app.backgroundColor = white;

  numW=Math.ceil(w/80) * 75;
  numH=Math.ceil(h/80) * 75;
  app.activeDocument.resizeCanvas (numW, numH);

// strip the extension off
var newfile = app.activeDocument;  
if(documents.length>0) {
    var thisIndexImage = getActiveDocumentIndex();
    var theDocs = app.documents; 
    if ( thisIndexImage != 0 ) {
        var openedBefore = theDocs[thisIndexImage - 1];
        } else {
        var openedBefore = theDocs[0];
        }
    app.activeDocument = openedBefore;
} else {
    alert ("You need to have any opened documents to apply this script.")
}

function getActiveDocumentIndex(){
     var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
     return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
}

var docRef = app.activeDocument;
var fileNameNoExtension = docRef.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
if ( fileNameNoExtension.length > 1 ) {
  fileNameNoExtension.length--;
 }
 fileNameNoExtension = fileNameNoExtension.join(".");
 app.activeDocument =newfile;
  
  
 var folderForTempFiles = Folder.temp.fsName;


   // create a new textfile and put the text into it
   var text = fileNameNoExtension
   var clipTxtFile =new File(folderForTempFiles + "/ClipBoard.txt"); 
   clipTxtFile.open('w'); 
   clipTxtFile.write(text); 
   clipTxtFile.close();

   // use the clip.exe to copy the contents of the textfile to the windows clipboard
   var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat"); 
   clipBatFile.open('w'); 
   clipBatFile.writeln("type \"" + folderForTempFiles + "\\" + "ClipBoard.txt\" | clip"); 
   clipBatFile.close(); 
   clipBatFile.execute();


參考資料:

No comments: