The business I work for creates laser engraved custom products. The engraver machine requires files to be in the psd format. Our website enables users to select a template and enter in what text they want. After they order, one of our workers opens the template in GIMP/Photoshop, switches out the text, then saves and uploads it. Seems simple enough, but when you're doing hundreds of these a day, seems like it's worth automating.
The main language I speak is python, but I've dabbled enough in other languages enough that I can do small projects. I see there are a few different PSD/photoshop modules out there (pywin32, pyps, psd-tools), but there either isn't enough documentation on them or they don't seem suitable for my purposes. In more detail, the only thing that needs to happen is to have a text layer added, where we can choose the font, location, and preferably things like whether or not it's bolded, italicized, etc., but that's not required. I've got a solution that can make a text layer (via win32com), but I can't find how to edit the different elements of the text.
import win32com.client
# Pieced together from
# http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html
# and
# http://rubypane.blogspot.com/2013/01/sample-python-script-to-control.html
psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open(r"C:\temp\blah.psd") # Opens a PSD file
doc = psApp.Application.ActiveDocument # Get active document object
layer = doc.ArtLayers[2] # Get the bottom-most layer
layers = doc.artLayers
artLayerRef = layers.add
artLayerRef.kind = 2 #Text layer
# Set the contents of the text layer.
textItemRef = artLayerRef.TextItem
textItemRef.Contents = "Hello, web!"
doc.Save()
That snippet of code produces a small text box without any formatting saying "Hello World!". Again, I'd like to be able to control where it's located, the font, and if possible, other elements of it as well. I'm also open to other solutions, whether it's creating the picture in another format then converting it to psd, working with another module/language, or any other solution your brilliant minds can think of. Worst case scenario, we keep on doing it manually. Thank you for any help!
textItemRef.position
for location,textItemRef.font
for font, etc. Search fortextItem
in the scripting reference pdf. – Sergey Kritskiy