search
HomeWeb Front-endPS TutorialPhotoShop 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
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
Photoshop: Advanced Techniques and ToolsPhotoshop: Advanced Techniques and ToolsApr 21, 2025 am 12:08 AM

Advanced features of Adobe Photoshop include advanced selection tools, layer blending modes, and actions and scripts. 1) Advanced selection tools such as the Quick Selection Tool and the Color Range Selection Tool can accurately select image areas. 2) Layer blending mode such as "overlapping" mode can create unique visual effects. 3) Actions and scripts can automate repetition of tasks and improve work efficiency.

Photoshop's Main Feature: Retouching and EnhancementPhotoshop's Main Feature: Retouching and EnhancementApr 20, 2025 am 12:07 AM

Photoshop's powerful functions in photo editing and enhancement include: 1. Use the "Repair Brush Tool" to remove acne, 2. Use the "Liquefaction Tool" to slim face, 3. Use the "Frequency Separation" technology to accurately retouch images. These functions are implemented through algorithms and image processing technology to optimize image processing effects.

Photoshop's Key Features: A Deep DivePhotoshop's Key Features: A Deep DiveApr 19, 2025 am 12:08 AM

Key features of Photoshop include layers and masks, adjustment tools, filters and effects. 1. Layers and masks allow independent editing of image parts. 2. Adjust tools such as brightness/contrast can modify image tone and brightness. 3. Filters and effects can quickly add visual effects. Mastering these features can help creative professionals achieve their creative vision.

Photoshop and Digital Art: Painting, Illustration, and CompositingPhotoshop and Digital Art: Painting, Illustration, and CompositingApr 18, 2025 am 12:01 AM

Photoshop's applications in digital art include painting, illustration and image synthesis. 1) Painting: Using brushes, pencils and mixing tools, the artist can create realistic effects. 2) Illustration: With vector and shape tools, artists can accurately draw complex graphics and add effects. 3) Synthesis: Using mask and layer blending mode, artists can seamlessly blend different image elements.

Advanced Photoshop Tutorial: Master Retouching & CompositingAdvanced Photoshop Tutorial: Master Retouching & CompositingApr 17, 2025 am 12:10 AM

Photoshop's advanced photo editing and synthesis technologies include: 1. Use layers, masks and adjustment layers for basic operations; 2. Use image pixel values ​​to achieve photo editing effects; 3. Use multiple layers and masks for complex synthesis; 4. Use "liquefaction" tools to adjust facial features; 5. Use "frequency separation" technology to perform delicate photo editing, these technologies can improve image processing level and achieve professional-level effects.

Using Photoshop for Graphic Design: Branding and MoreUsing Photoshop for Graphic Design: Branding and MoreApr 16, 2025 am 12:02 AM

The steps to using Photoshop for brand design include: 1. Use the Pen tool to draw basic shapes, 2. Add shadows and highlights through layer styles, 3. Adjust colors and details, 4. Use smart objects and actions to automatically generate different versions of the design. Photoshop helps designers create and optimize brand elements with the flexibility of layers and masks, ensuring consistency and professionalism of designs, from simple logos to complex branding guides.

Photoshop's Subscription Model: What You Get for Your MoneyPhotoshop's Subscription Model: What You Get for Your MoneyApr 15, 2025 am 12:17 AM

Photoshop's subscription model is worth buying. 1) Users can access the latest version and use across devices at any time. 2) The subscription fee is low, and continuous updates and technical support are provided. 3) Advanced functions such as neural filters can be used for complex image processing. Despite the high long-term costs, its convenience and feature updates are valuable to professional users.

Photoshop: Investigating Free Trials and Discount OptionsPhotoshop: Investigating Free Trials and Discount OptionsApr 14, 2025 am 12:06 AM

You can get the access to Photoshop in the most economical way: 1. Experience the software features with a 7-day free trial; 2. Find student or teacher discounts, as well as seasonal promotions; 3. Use coupons on third-party websites; 4. Subscribe to Adobe CreativeCloud's monthly or annual plan.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software