Home Web Front-end PS Tutorial PhotoShop Scripting Guide

PhotoShop Scripting Guide

Feb 24, 2017 am 09:27 AM
photoshop

PhotoshopScript language

Photoshop supports three scripting languages: AppleScript, VBScript, and JavaScript. Among them, AppleScript is for Apple system, VBScript is for Windows operating system, and JavaScript is compatible with Apple and Windows operating systems.

# This Photoshop can recognize the JavaScript script, and its script file suffix must be*.jsx or*.js files. You can open and execute JavaScript script files through File >Scripts >Browse.

PhotoshopObject Model

DOM (Document Object Model) is an API (Application Programming Interface). You can apply scripting language through DOM Perform various operations.

JavaScriptScript

1. Hello World example

The operation of this example is as follows: 1. Open Photoshop; 2. Create a new file; 3. Create a new ArtLayer layer; 4. Convert the ArtLayer to a text layer; 5. Set the text content to "Hello World".

The JavaScript script language is:

//Set the unit

app. preferences.rulerUnits = Units.INCHES

// Create a new file of 2*4INCHES

var docRef = app.documents.add( 2, 4 )

//Create a newArtLayer Layer

var artLayerRef = docRef.artLayers.add()

// Set the ArtLayer layer to the text layer

artLayerRef.kind = LayerKind.TEXT

//Set text layer text content

var textItemRef = artLayerRef.textItem

textItemRef.contents = " Hello World"

//Release reference

docRef = null

artLayerRef = null

textItemRef = null

The implementation effect is:

2. Obtain the Application object

You can obtain the Photoshop Application object through the predefined global object app. The following example illustrates how to obtain a Document file:

var docRef = app.documents[0]

The above expression can also be written as:

var docRef = documents[0]

3. Create a new object

You can create a new PSD file through File > New. For other types, such as layers, channels, paths, etc., you can create new ones using the menu or other methods. In JavaScript scripts, you can create new objects through add(). For example:

1) Create a new PSD file

documents.add() or app.documents.add()

2) Create a new ArtLayer layer

documents[0].artLayers.add()

4. Set the activation object

1) Set activation file

var docRef = app.documents[0]

app.activeDocument= docRef

2) Set the active ArtLayer layer

docRef.activeLayer = docRef.layers[0]

3) Set the activation channel

docRef.activeChannels = new Array(docRef.channels[0], docRef.channels[2])

5. Open a file

Because Photoshop can open a variety of formats Various, so you can use the open/Open/open() command to open an existing file.

1) Open a PSD file

var fileRef = File("C:/Users/Administrator/Desktop/test.psd")

var docRef = app.open(fileRef)

2) Open a Pdf file

//Set units

var originalRulerUnits = app.preferences.rulerUnits

app.preferences.rulerUnits = Units.PIXELS

//Get the name of the open file

var fileRef = new File("C:/Users/Administrator/Desktop/myfile.pdf")

//Create a new onePDFOpenOptions

var pdfOpenOptions = new PDFOpenOptions

pdfOpenOptions.antiAlias ​​= true

pdfOpenOptions.mode = OpenDocumentMode.RGB

pdfOpenOptions.resolution = 72

pdfOpenOptions.page = 3

//Open the file

app.open( fileRef, pdfOpenOptions )

6. Save the file

The file formats that Photoshop can save are as follows:

1) Save as jpg image

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 object

Photoshop object model It contains two layer objects: layer (ArtLayer) and group (Layer Set).

1) Create an ArtLayer layer object

//New file

app.documents.add ()

//New layer

##var layerRef = app.activeDocument.artLayers.add()

//Set layer name

layerRef.name = "MyBlendLayer"

layerRef.blendMode = BlendMode.NORMAL

2) Create a group

//New files and layers

app.documents.add()

var layer=app.activeDocument.artLayers.add()

layer.name="layer"

//New group and layer

var newLayerSetRef = app.activeDocument .layerSets.add()

newLayerSetRef.name="layerset"

##var layerset=newLayerSetRef.artLayers.add()

layerset.name="layerset"

7. Apply Layer Set object

You can move a layer to a group, or You can perform layer linking and other operations.

1) Copy the layer to the group

//

Create a new file, create a new layer, create a new group, and copy the layer to the group

var docRef = app.documents.add()

docRef.artLayers.add()

var layerSetRef = docRef.layerSets.add()

var layerRef = docRef.artLayers[0].duplicate(layerSetRef,ElementPlacement.PLACEATEND)

2) Link layer

var layerRef1 = docRef.artLayers.add()

var layerRef2 = docRef.artLayers.add()

layerRef1.link(layerRef2)

8. Apply text object

1) Convert ArtLayer to a text layer.

var newLayerRef = docRef.artLayers.add()

newLayerRef.kind = LayerKind.TEXT

2) Give Add text to the text layer

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. Application selection object

1) Create and define selection

var docRef = app.documents.add(500, 500)

var shapeRef = [

[0,0],

[0,100],

[100,100],

[100,0]

##]

2) Add border

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) Inverse selection

var selRef = app.activeDocument.selection

selRef.invert()

4) Expansion, infection, eclosion

var selRef = app.activeDocument.selection

selRef.expand( 5 )

selRef.contract( 5 )

selRef.feather( 5 )


Please pay attention to more PhotoShop script guide related articles PHP Chinese website!



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I use Photoshop for creating social media graphics? How do I use Photoshop for creating social media graphics? Mar 18, 2025 pm 01:41 PM

The article details using Photoshop for social media graphics, covering setup, design tools, and optimization techniques. It emphasizes efficiency and quality in graphic creation.

How do I prepare images for web use in Photoshop (file size, resolution, color space)? How do I prepare images for web use in Photoshop (file size, resolution, color space)? Mar 13, 2025 pm 07:28 PM

Article discusses preparing images for web use in Photoshop, focusing on optimizing file size, resolution, and color space. Main issue is balancing image quality with quick loading times.

How do I use Photoshop's Content-Aware Fill and Content-Aware Move tools effectively? How do I use Photoshop's Content-Aware Fill and Content-Aware Move tools effectively? Mar 13, 2025 pm 07:35 PM

Article discusses using Photoshop's Content-Aware Fill and Move tools effectively, offering tips on selecting source areas, avoiding mistakes, and adjusting settings for optimal results.

How do I calibrate my monitor for accurate color in Photoshop? How do I calibrate my monitor for accurate color in Photoshop? Mar 13, 2025 pm 07:31 PM

Article discusses calibrating monitors for accurate color in Photoshop, tools for calibration, effects of improper calibration, and recalibration frequency. Main issue is ensuring color accuracy.

How do I use Photoshop's video editing capabilities? How do I use Photoshop's video editing capabilities? Mar 18, 2025 pm 01:37 PM

The article explains how to use Photoshop for video editing, detailing steps to import, edit, and export videos, and highlighting key features like the Timeline panel, video layers, and effects.

How do I create animated GIFs in Photoshop? How do I create animated GIFs in Photoshop? Mar 18, 2025 pm 01:38 PM

Article discusses creating and optimizing animated GIFs in Photoshop, including adding frames to existing GIFs. Main focus is on balancing quality and file size.

How do I prepare images for web using Photoshop (optimize file size, resolution)? How do I prepare images for web using Photoshop (optimize file size, resolution)? Mar 18, 2025 pm 01:35 PM

Article discusses optimizing images for web using Photoshop, focusing on file size and resolution. Main issue is balancing quality and load times.

How do I prepare images for print using Photoshop (resolution, color profiles)? How do I prepare images for print using Photoshop (resolution, color profiles)? Mar 18, 2025 pm 01:36 PM

The article guides on preparing images for print in Photoshop, focusing on resolution, color profiles, and sharpness. It argues that 300 PPI and CMYK profiles are essential for quality prints.

See all articles