Month: October 2016
Photoshop Scripting and Automation
One of the nice features of many Adobe applications is the ability to automate repetitive or highly detailed sequences of tasks. The simple solution of using actions is more than enough for most purposes but sometimes you need more flexibility. That is where scripting can be useful. The obvious choice for running scripts within an Adobe application is ExtendScript or javascript. VBScript is also supported in Photoshop but it is probably not the best choice all around.
Simple External Automation
There is another option for using Photoshop functionality that I will be talking about here. If you are running Windows you can automate Photoshop and some other Adobe applications with OLE automation objects. This opens up possibilities for using Photoshop functionality within applications using general purpose programming languages such as C# or VB.Net. Ole Automation only makes sense if you have a need to combine Photoshop capabilities and other functionality that is not easily available within Photoshop. For instance, if you plan to use SQL Server or SQLlite along with image processing then building scripts that run entirely within Photoshop is probably not the best option. The application I describe is a standalone Windows desktop app built using Visual Studio 2015, VB.Net and SQLite.
Here is a small code snippet from my PSAuto class to give you a sense of how OLE automation might be done in VB.Net. The code uses Photoshop references that were added to the working project. These references must be added to allow Photoshop functionality to be accessed within Dot Net. This is just one possible approach that could be used for automation.
Imports Photoshop Public Structure pDocInfo Public _title As String Public _author As String Public _authPos As String Public _capt As String Public _captionWrtr As String Public _keywords As String Public _copyrighted As PsCopyrightedType Public _copyrightNotice As String Public _ownerURL As String End Structure Private Function doCreatPsApp() As Application If _psApp Is Nothing Then _psApp = New Application() _psApp.DisplayDialogs = PsDialogModes.psDisplayNoDialogs End If Return _psApp End Function Private Function doOpenPSDoc(ByVal path As String) As Document Dim psdoc As Document = Nothing Try Dim psapp As Application = doCreatPsApp() psdoc = psapp.Open(path) Catch ex As Exception Throw End Try Return psdoc End Function Public Function PopulateDocInfo(ByVal doc As Document, ByVal dinfo As pDocInfo) As Document doc.Info.Title = dinfo._title doc.Info.Author = dinfo._author doc.Info.AuthorPosition = dinfo._authPos doc.Info.Caption = dinfo._capt doc.Info.CaptionWriter = dinfo._captionWrtr doc.Info.Keywords = dinfo._keywords doc.Info.Copyrighted = dinfo._copyrighted doc.Info.CopyrightNotice = dinfo._copyrightNotice doc.Info.OwnerUrl = dinfo._ownerURL Return doc End Function
Building Calendars
Over the past few months I have been publishing calendar downloads on my blog with a new featured photograph every week. I release two versions of each calendar with North America or international week formatting. The difference being that one has weekdays starting on Sunday and the other Monday. Each calendar includes a 5×7 high resolution image at 300ppi in horizontal or vertical orientation. My approach to creating calendars is to use .psd files of static calendar content as templates. New images and text are then added and secure PDF documents are generated.
Here is the process for publishing the calendars and blog post images:
- Select the featured image for the week
- Add file and copyright information to the source image file
- Export a version of the image having a horizontal dimension of 600 pixels or less for publishing online in the blog post
- Create a 5×7 300ppi version of the image in horizontal or vertical format for the weekly calendars
- Open Photoshop and load the appropriate North America and international calendar templates
- Insert the photo into each template as a layer
- Position the photo in the template
- Edit image title text
- Position the image title text relative to the image
- Publish the completed calendars as secure PDF documents
- Move finished documents to output folders
- Write a blog post to discuss the image
Advantages of Automation
The steps outlined above are repetitive and tedious work. Just the kind of thing the computer should handle for a user. The entire workflow for creating PDF calendars and blog post images can be automated with a little work. The process can also easily be driven by information stored in a database using something like SQLite. The database can store everything including calendar templates, original source images, logo images, copyright information, titles, text data, calendar layout configurations, processing logs, etc. The user need only select a source image and enter some text fields. The application handles all aspects of document creation and information storage autonomously. The whole process takes a few seconds at most. Using a data driven approach also allows previous documents to be regenerated on demand.
My application is around 80% complete as of now. The prototype app can select and size images, add standard and image specific file/copyright information, load appropriate calendar templates, modify text content and add images as layers to the calendar templates. All information is stored in a local SQLite database. The app can use either an existing instance of Photoshop or start a new instance as necessary for processing.
Broader Uses for Scripting
My ultimate goal is to be able to automate any adobe application that supports scripting capability using ExtendScript or Javascript. That allows development of cross application and cross platform functionality. Depending upon the need there are also many possibilities for combining internal and external scripting. For instance Python comes to mind as a compliment to Javascript. Also combining scripting and actions seems interesting.
Of course application scripting is not something everyone will need or want to do. It is good to know the capability exists just in case you ever need it. For me it is a way to combine my passions for photography and code.
Architecture
By inclination I’m a regional photographer. Regional mostly implies within a few hundred miles for most of my photography with a few exceptions. I was born and raised in Utah and I have a strong attachment to the Four Corners States having lived in three and traveled in all.
By far the most naturally spiritual place I’ve ever encountered is Northern New Mexico. It is a land with civilizations going back at least a thousand years and probably far longer. The Spanish came to civilize the Puebloan peoples in 1598 and destroyed much of the rich culture that thrived there. Thankfully they didn’t succeed completely. They did leave behind a blend of cultures and religions including the beginnings of iconic New Mexico colonial architecture.
Part of the reason why Spanish architecture is so well adapted here is because it fits comfortably with traditional Puebloan building styles. The existing construction techniques practiced by native peoples were perfect for adobe churches and official buildings. A quick stroll around any town in New Mexico will make the point about how well New Mexican architecture has served the people for hundreds of years.