如何通过自动化Photoshop使用JavaScript节省时间

2023-10-25 05:30

本文主要是介绍如何通过自动化Photoshop使用JavaScript节省时间,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

java ps

What could JavaScript POSSIBLY have to do with an Image Editor? Using this platform independent scripting language, today we’ll learn to create automated tasks either Mac or PC versions of Photoshop will run. Photoshop has an API (Application Programming Interface) that allows those with know-how to create scripted tasks and automate even surprisingly complicated actions. With the advantage of using a language as powerful as JavaScript, geeky programmers can come up with clever uses of conditional logic, variables, and sometimes applications outside of Photoshop. Take a look through these simple JavaScripts and learn how to use them in Photoshop.

JavaScript可能与图像编辑器有什么关系? 现在,使用这种独立于平台的脚本语言,我们将学习创建可以运行Mac或PC版本的Photoshop的自动化任务。 Photoshop有一个API(应用程序编程接口),使具有专门知识的人员可以创建脚本任务并自动执行甚至令人惊讶的复杂动作。 利用使用像JavaScript这样强大的语言的优势,令人讨厌的程序员可以想出条件逻辑,变量以及有时在Photoshop之外的应用程序的巧妙用法。 浏览这些简单JavaScript,并学习如何在Photoshop中使用它们。

你好,世界! (Hello World!)

sshot-705

The most basic of basic programs, the Photoshop CS5 Scripting Guide provides a sample “Hello World” script to help us leap in and get started. We can see a few things going on here: units are set to inches, a new document is created, and text is added simply, using the Photoshop API.

《 Photoshop CS5脚本指南》是最基本的基本程序,它提供了一个示例“ Hello World”脚本,可帮助我们快速入门。 我们可以看到这里发生了一些事情:使用Photoshop API将单位设置为英寸,创建新文档,并简单地添加文本。

To create this basic document, you’ll need a text editor like Komodo Edit, Notepad 2, or Fraise for Mac. Make sure to save your JavaScript file as a .JSX or a .JS file. Photoshop will easily read either in OS X or Windows. Save your file in any place you can locate later.

要创建此基本文档,您需要一个文本编辑器,例如Komodo Edit , Notepad 2或Fraise for Mac 。 确保将JavaScript文件另存为.JSX或.JS文件。 Photoshop可以在OS X或Windows中轻松阅读。 将文件保存在以后可以找到的任何位置。

Make sure you download the Scripting Guide for your version of Photoshop and copy the text from the PDF, rather than retyping it!

请确保您下载的脚本指南为你的Photoshop版本,并从PDF复制的文字,而不是重新键入它!

sshot-721

Open Photoshop. Any version dating back to Creative Suite 2 will work fine, although your code may be different.

打开Photoshop。 可以追溯到Creative Suite 2的任何版本都可以正常工作,尽管您的代码可能有所不同。

sshot-704

Navigate to File > Scripts > Browse to look for your saved JavaScript file.

导航到“文件”>“脚本”>“浏览”以查找您保存JavaScript文件。

sshot-708

Navigate to where you have saved your “Hello World” JavaScript file and load it.

导航到保存“ Hello World” JavaScript文件的位置并加载它。

sshot-709

Photoshop creates a document to the specifications in the JavaScript file: 2 by 4 inches, with the text object “Hello, World.”

Photoshop会按照JavaScript文件中的规格创建一个文档:2 x 4英寸,文本对象为“ Hello,World”。

sshot-710

Naturally, this opens up all sort of possibilities. Let’s take a quick look through another basic one, using these same simple tools.

自然地,这开辟了各种可能性。 让我们使用这些相同的简单工具快速浏览另一种基本工具。

使用事件管理器创建新页面 (Creating a New Page with the Events Manager)

sshot-700

Simply editing the “Hello World” document, we can create a script that will create a standard paper size at a high resolution. The bits about the text object are removed and the comments have been changed, as well.

只需编辑“ Hello World”文档,我们就可以创建一个脚本,以高分辨率创建标准纸张尺寸。 有关文本对象的位也已删除,注释也已更改。

Note that the app.documents.add has different values than our “Hello World” file. “8.5” and “11” are still inches, but 300 is the resolution of the file.

请注意, app.documents.add与我们的“ Hello World”文件具有不同的值。 “ 8.5”和“ 11”仍然是英寸,但文件的分辨率为300。

Here is the code to copy and paste, if you are so inclined:

如果您愿意,以下是复制和粘贴的代码:

// New Canvas Script

// Remember current unit settings and then set units to

// the value expected by this script

var originalUnit = preferences.rulerUnits

preferences.rulerUnits = Units.INCHES

// Create a new 8.5 x 11 inch document and assign it to a variable

var docRef = app.documents.add( 8.5, 11, 300)

// Release references

docRef = null

artLayerRef = null

textItemRef = null

// Restore original ruler unit setting

app.preferences.rulerUnits = originalUnit

//新的画布脚本

//记住当前单位设置,然后将单位设置为

//此脚本期望的值

var originalUnit = preferences.rulerUnits

preferences.rulerUnits =单位。英寸

//创建一个新的8.5 x 11英寸的文档并将其分配给变量

var docRef = app.documents.add(8.5,11,300)

//发布参考

docRef =空

artLayerRef = null

textItemRef = null

//恢复原始标尺单位设置

app.preferences.rulerUnits = originalUnit

sshot-697

Save your document as a .JS or a .JSX file anywhere you care to store it.

将文档另存为.JS或.JSX文件。

sshot-712

If you work on multiple machines with Photoshop, you may wish to save it in your Dropbox folder.

如果您使用Photoshop在多台计算机上工作,则可能希望将其保存在Dropbox文件夹中。

sshot-721

Return to Photoshop.

返回到Photoshop。

sshot-713

Under the same File > Scripts menu, you’ll find “Script Events Manager.” Open it.

在同一文件>脚本菜单下,您会找到“脚本事件管理器”。 打开它。

sshot-715

You’ll get this dialog box. You can apply Scripts to many different Events, but for this one, we’ll have Photoshop run our script upon “Start Application.” You can browse to your script by clicking the pull-down menu that reads “Clean Listener” in the illustrated screenshot.

您将获得此对话框。 您可以将脚本应用于许多不同的事件,但是对于这一事件,我们将让Photoshop在“启动应用程序”上运行脚本。 您可以通过单击所示屏幕截图中显示为“ Clean Listener”的下拉菜单来浏览至脚本。

sshot-716

Find your JavaScript file.

查找您JavaScript文件。

sshot-717

Add your custom script and click “Done.”

添加您的自定义脚本,然后单击“完成”。

sshot-719

Restarting Photoshop, we find it opens an 8.5 inch by 11 inch page at 300 dpi resolution, just as we scripted.

重新启动Photoshop,我们发现它以300 dpi的分辨率打开了8.5英寸x 11英寸的页面,就像我们编写的脚本一样。


Nearly everything that can be done in Photoshop with a keyboard and mouse can be done in JavaScript (or additionally Applescript or Visual Basic, although those are platform-dependent). Experiment with your own JavaScripting skills, or come back to How-To Geek for our own takes on automating Photoshop with JavaScript!
几乎可以在Photoshop中使用键盘和鼠标完成的所有操作都可以在JavaScript中完成(或另外通过Applescript或Visual Basic完成,尽管它们是与平台相关的)。 尝试使用您自己JavaScript技能,或者回到How-To Geek,了解我们自己使用JavaScript自动执行Photoshop的需要!

JavaScript, Applescript, or Visual basic have guides for scripting available for download, going as far back as Photoshop CS2. Download any and all of them here.

JavaScript,Applescript或Visual Basic具有可用于下载脚本的指南,其历史可以追溯到Photoshop CS2。 在此处下载任何一个。

翻译自: https://www.howtogeek.com/howto/34334/how-to-use-javascript-to-save-time-by-automating-photoshop/

这篇关于如何通过自动化Photoshop使用JavaScript节省时间的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/280303

相关文章

Spring Boot 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

Mac系统下卸载JAVA和JDK的步骤

《Mac系统下卸载JAVA和JDK的步骤》JDK是Java语言的软件开发工具包,它提供了开发和运行Java应用程序所需的工具、库和资源,:本文主要介绍Mac系统下卸载JAVA和JDK的相关资料,需... 目录1. 卸载系统自带的 Java 版本检查当前 Java 版本通过命令卸载系统 Java2. 卸载自定

springboot下载接口限速功能实现

《springboot下载接口限速功能实现》通过Redis统计并发数动态调整每个用户带宽,核心逻辑为每秒读取并发送限定数据量,防止单用户占用过多资源,确保整体下载均衡且高效,本文给大家介绍spring... 目录 一、整体目标 二、涉及的主要类/方法✅ 三、核心流程图解(简化) 四、关键代码详解1️⃣ 设置

Java Spring ApplicationEvent 代码示例解析

《JavaSpringApplicationEvent代码示例解析》本文解析了Spring事件机制,涵盖核心概念(发布-订阅/观察者模式)、代码实现(事件定义、发布、监听)及高级应用(异步处理、... 目录一、Spring 事件机制核心概念1. 事件驱动架构模型2. 核心组件二、代码示例解析1. 事件定义

SpringMVC高效获取JavaBean对象指南

《SpringMVC高效获取JavaBean对象指南》SpringMVC通过数据绑定自动将请求参数映射到JavaBean,支持表单、URL及JSON数据,需用@ModelAttribute、@Requ... 目录Spring MVC 获取 JavaBean 对象指南核心机制:数据绑定实现步骤1. 定义 Ja

python使用库爬取m3u8文件的示例

《python使用库爬取m3u8文件的示例》本文主要介绍了python使用库爬取m3u8文件的示例,可以使用requests、m3u8、ffmpeg等库,实现获取、解析、下载视频片段并合并等步骤,具有... 目录一、准备工作二、获取m3u8文件内容三、解析m3u8文件四、下载视频片段五、合并视频片段六、错误

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再