|
導讀Adobe Photoshop,簡稱“PS”,是由Adobe Systems開發和發行的圖像處理軟件。Photoshop主要處理以像素所構成的數字圖像。使用其眾多的編修與繪圖工具,可以有效地進行圖片... Adobe Photoshop,簡稱“PS”,是由Adobe Systems開發和發行的圖像處理軟件。Photoshop主要處理以像素所構成的數字圖像。使用其眾多的編修與繪圖工具,可以有效地進行圖片編輯工作。ps有很多功能,在圖像、圖形、文字、視頻、出版等各方面都有涉及。 Photoshop腳本語言Photoshop支持三種腳本語言:AppleScript,VBScript,JavaScript。其中AppleScript為蘋果系統,VBScript為Windows操作系統,JavaScript兼容蘋果和Windows操作系統。
Photoshop可識別JavaScript腳本,其腳本文件后綴必須為*.jsx或者*.js文件。你可以通過文件(File) >腳本(Scripts) >瀏覽(Browse)打開并執行JavaScript腳本文件。 Photoshop對象模型 DOM(Document Object Model)即為一個API(Application Programming Interface),你可以通過DOM應用腳本語言執行各種操作。
JavaScript腳本 1、Hello World示例 本實例操作如下:1、打開Photoshop;2、新建一個文件;3、新建一個ArtLayer圖層;4、將ArtLayer轉換為文本圖層;5、將文本內容設置為“Hello World”。
JavaScript腳本語言為: //設置單位 app.preferences.rulerUnits = Units.INCHES // 新建一個2*4INCHES的文件 var docRef = app.documents.add( 2, 4 ) //新建一個ArtLayer圖層 var artLayerRef = docRef.artLayers.add() //設置ArtLayer圖層為文本圖層 artLayerRef.kind = LayerKind.TEXT //設置文本圖層文字內容 var textItemRef = artLayerRef.textItem textItemRef.contents = "Hello World" //釋放參考 docRef = null artLayerRef = null textItemRef = null 實現效果為:
2、獲得Application對象 你可以通過預定義的全局對象app獲得Photoshop Application對象。下面的例子說明了如何獲取一個Document文件: var docRef = app.documents[0] 上面的表達式也可寫為: var docRef = documents[0] 3、新建一個對象 你可以通過File > New新建一個PSD文件。別的類型的如圖層、通道、路徑等,你可以用過菜單或者別的方式新建。在JavaScript腳本中,你可以通過add()實現對象的新建。例如: 1) 新建一個PSD文件 documents.add()或者app.documents.add() 2) 新建一個ArtLayer圖層 documents[0].artLayers.add() 4、設置激活對象 1) 設置激活文件 var docRef = app.documents[0] app.activeDocument= docRef 2) 設置激活ArtLayer圖層 docRef.activeLayer = docRef.layers[0] 3) 設置激活通道 docRef.activeChannels = new Array(docRef.channels[0], docRef.channels[2]) 5、打開一個文件 由于Photoshop能打開的格式多種多樣,所以你可以選用open/Open/open()命令打開一個已存在的文件。
1) 打開一個PSD文件 var fileRef = File("C:/Users/Administrator/Desktop/test.psd") var docRef = app.open(fileRef) 2) 打開一個Pdf文件 //設置單位 var originalRulerUnits = app.preferences.rulerUnits app.preferences.rulerUnits = Units.PIXELS //獲得打開文件的名稱 var fileRef = new File("C:/Users/Administrator/Desktop/myfile.pdf") //新建一個PDFOpenOptions var pdfOpenOptions = new PDFOpenOptions pdfOpenOptions.antiAlias = true pdfOpenOptions.mode = OpenDocumentMode.RGB pdfOpenOptions.resolution = 72 pdfOpenOptions.page = 3 //打開文件 app.open( fileRef, pdfOpenOptions ) 6、保存文件 Photoshop可保存的文件格式如下:
1) 保存為jpg圖片 jpgFile = new File( "C:/Users/Administrator/Desktop/test.jpg" ) jpgSaveOptions = new JPEGSaveOptions() jpgSaveOptions.embedColorProfile = true jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE jpgSaveOptions.matte = MatteType.NONE jpgSaveOptions.quality = 1 app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true,Extension.LOWERCASE) 6、layer層對象 Photoshop對象模型里面包含兩個layer層對象:圖層(ArtLayer)和組(Layer Set)。 1) 創建一個ArtLayer圖層對象 //新建文件 app.documents.add() //新建層 var layerRef = app.activeDocument.artLayers.add() //設置層名稱 layerRef.name = "MyBlendLayer" layerRef.blendMode = BlendMode.NORMAL 2) 創建一個組 //新建文件和圖層 app.documents.add() var layer=app.activeDocument.artLayers.add() layer.name="layer" //新建組和圖層 var newLayerSetRef = app.activeDocument.layerSets.add() newLayerSetRef.name="layerset" var layerset=newLayerSetRef.artLayers.add() layerset.name="layerset" 7、應用Layer Set對象 你可以將一個圖層移到一個組里,也可以進行圖層鏈接等操作。 1) 復制圖層到組 //新建文件,新建圖層,新建組,并復制圖層到組 var docRef = app.documents.add() docRef.artLayers.add() var layerSetRef = docRef.layerSets.add() var layerRef = docRef.artLayers[0].duplicate(layerSetRef,ElementPlacement.PLACEATEND) 2) 鏈接圖層 var layerRef1 = docRef.artLayers.add() var layerRef2 = docRef.artLayers.add() layerRef1.link(layerRef2) 8、應用文本對象 1) ArtLayer轉換為文本層。 var newLayerRef = docRef.artLayers.add() newLayerRef.kind = LayerKind.TEXT 2) 給文本層添加文字 var textLayerRef = docRef.artLayers.add() textLayerRef.name = "my text" textLayerRef.kind = LayerKind.TEXT var textItemRef = docRef.artLayers["my text"].textItem textItemRef.contents = "Hello, World!" textItemRef.justification = Justification.RIGHT 9、應用選擇對象 1) 創建和定義選擇 var docRef = app.documents.add(500, 500) var shapeRef = [ [0,0], [0,100], [100,100], [100,0] ] 2) 添加邊框 strokeColor = new solidColor strokeColor.cmyk.cyan = 20 strokeColor.cmyk.magenta = 50 strokeColor.cmyk.yellow = 30 strokeColor.cmyk.black = 0 app.activeDocument.selection.stroke (strokeColor, 2,StrokeLocation.OUTSIDE, ColorBlendMode.VIVIDLIGHT, 75, false) 3) 反向選擇 var selRef = app.activeDocument.selection selRef.invert() 4) 擴展、感染、羽化 var selRef = app.activeDocument.selection selRef.expand( 5 ) selRef.contract( 5 ) selRef.feather( 5 ) 更多PhotoShop腳本指南相關文章請關注PHP中文網!
Photoshop默認保存的文件格式,可以保留所有有圖層、色版、通道、蒙版、路徑、未柵格化文字以及圖層樣式等。 |
溫馨提示:喜歡本站的話,請收藏一下本站!