|
Purpose The purpose of this project is to demonstrate how you can run Adobe Photoshop from a webpage in order to create images; this is accomplished by the use of Adobe's JSX format (which Photoshop reads in order to create an image). Prior to this free release of methods and source code, it was virtually IMPOSSIBLE to find reliable source code and step-by-step instructions on how to use Adobe Photoshop CS2+ on a web site through a regular web page and have it perform tasks such as creating an image on a web site. |
<%
dim appName, cmdLocation, locale appName = "name_of_asp_page.asp" cmdLocation = "c:\windows\system32\" locale = Server.MapPath(appName) : locale = replace(locale, appName, "") set sbatch = server.CreateObject("WScript.Shell") set labor = sbatch.Exec(cmdLocation & "cmd.exe /C echo test >> " & locale & "temp.txt") sbatch.close set sbatch = nothing : set labor = nothing set appName = nothing : set cmdLocation = nothing : set locale = nothing %>
<%
dim appName, dbJsx, locale
appName = "name_of_asp_page.asp"
dbJsx = "my_jsx.jsx"
locale = Server.MapPath(appName) : locale = replace(locale, appName, "")
set sbatch = server.CreateObject("WScript.Shell")
sbatch.Run locale & dbJsx, 0, FALSE
sbatch.close
set sbatch = nothing : set appName = nothing : set dbJsx = nothing : set locale = nothing
%>
<%
dim cmdLocation
cmdLocation = "c:\windows\system32\"
set sbatch = Server.CreateObject("WScript.Shell")
set labor = sbatch.Exec(cmdLocation & "cmd.exe /C taskkill /F /IM Photoshop.exe")
sbatch.close
set sbatch = nothing : set labor = nothing
%>
<html> <body> <form method="post" action="make_image.asp"> <input type="text" name="text" size="50" maxlength="50" /> Enter some text to put into the image<br /> <input type="submit" value="Create Custom Image" /> </form> </body> </html>
<%
dim appName, dbJsx, errInfo, height, width, title, tcolor, bcolor, name, txt_font, txt_size, txt_horizontalScale, txt_verticalScale, txt_translateX, txt_translateY, gif_colors
appName = "make_image.asp" ' Name of this application
dbJsx = "adobe_jsx.jsx" ' Adobe JSX File Containing Commands for Photoshop CS2+
errInfo = "" ' Catch Error Output From Execution
height = 65 ' Default height of image
width = 490 ' Default width of image
title = "This is a test" ' Default title of image
tcolor = "FFFFFF" ' Default text color of image
bcolor = "000000" ' Default background color of image
name = "test" ' Default filename of image
txt_font = "Verdana" ' Default text font type to use in image
txt_size = 25 ' Default font size
txt_horizontalScale = 100 ' Default font horizontal scale
txt_verticalScale = 115 ' Default font vertical scale
txt_translateX = -35 ' Default font X translation
txt_translateY = 37 ' Default font Y translation
gif_colors = 16 ' Default GIF palette
' GET Form Data
title = request.form("text")
' ERROR Accumulation
Sub HandleError(ecode, emsg)
errInfo = errInfo & "Error Code: " & ecode & "<br />Error Description: " & emsg & "<br />"
End Sub
' ERROR Probe
Sub ProbeError
If Err.Number <> 0 Then
HandleError Err.Number, Err.Description
Error.Clear
End If
On Error GoTo 0
End Sub
' BEGIN Error Monitoring
Err.Clear
On Error Resume Next
locale = Server.MapPath(appName) : locale = replace(locale, appName, "")
local_photoshop = replace(locale, "\", "\\")
' FILTER
tcolor = replace(tcolor, "#", "") : tcolor = replace(tcolor, ";", "")
bcolor = replace(bcolor, "#", "") : bcolor = replace(bcolor, ";", "")
title = replace(title, """", "\""") : title = replace(title, "“", "\""")
title = replace(title, "”", "\""") : title = replace(title, "‘", "'")
title = replace(title, "’", "'")
' BUILD the JSX File
set paper = Server.CreateObject("Scripting.FileSystemObject")
if paper.fileExists(locale & dbJsx) = False Then
' Create New JSX Content
set pen = paper.OpenTextFile(locale & dbJsx, 2, True)
Else
' Overwrite Existing JSX Content
set pen = paper.OpenTextFile(locale & dbJsx, 2, False)
End if
' Actually Build The JSX Here
pen.WriteLine "#target photoshop"
pen.WriteLine "app.displayDialogs = DialogModes.NO;" ' Do not display any dialog boxes for the entire script's execution. Will catch font substitution dialog boxes that may come up.
pen.WriteLine "var imageHeight = " & height & ";"
pen.WriteLine "var imageWidth = " & width & ";"
pen.WriteLine "var imageText = """ & title & """;"
pen.WriteLine "var textColor = """ & tcolor & """;"
pen.WriteLine "var fillColor = """ & bcolor & """;"
pen.WriteLine "var fileLocation = """ & local_photoshop & """;"
pen.WriteLine "var originalUnit = preferences.rulerUnits;"
pen.WriteLine "preferences.rulerUnits = Units.PIXELS;"
pen.WriteLine "backgroundColor.rgb.hexValue = fillColor;"
pen.WriteLine "foregroundColor.rgb.hexValue = textColor;"
pen.WriteLine "var headerDoc = documents.add(imageWidth, imageHeight, 72, imageText, NewDocumentMode.RGB, DocumentFill.BACKGROUNDCOLOR, 1);"
pen.WriteLine "headerDoc.DialogModes = DialogModes.NO;" ' Do not display dialog boxes relating to "headerDoc" specifically. Will not catch any font substitution dialog boxes.
pen.WriteLine "var textLayer = headerDoc.artLayers.add();"
pen.WriteLine "textLayer.kind = LayerKind.TEXT;"
pen.WriteLine "textLayer.textItem.contents = imageText;"
pen.WriteLine "textLayer.textItem.font = """ & txt_font & """;"
pen.WriteLine "textLayer.textItem.color = foregroundColor;"
pen.WriteLine "textLayer.textItem.size = " & txt_size & ";"
pen.WriteLine "textLayer.textItem.horizontalScale = " & txt_horizontalScale & ";"
pen.WriteLine "textLayer.textItem.verticalScale = " & txt_verticalScale & ";"
pen.WriteLine "textLayer.textItem.antiAliasMethod = AntiAlias.SHARP;"
pen.WriteLine "textLayer.translate(" & txt_translateX & ", " & txt_translateY & ");"
pen.WriteLine "var headerSaveOptions = new GIFSaveOptions();"
pen.WriteLine "headerSaveOptions.colors = " & gif_colors & ";"
pen.WriteLine "var headerFile = new File(fileLocation + """ & name & ".gif"");"
pen.WriteLine "headerDoc.flatten();"
pen.WriteLine "headerDoc.saveAs(headerFile,headerSaveOptions,true,Extension.LOWERCASE);"
pen.WriteLine "headerDoc.close(SaveOptions.DONOTSAVECHANGES);"
pen.WriteLine "preferences.rulerUnits = originalUnit;"
pen.WriteLine "imageHeight = null;"
pen.WriteLine "imageWidth = null;"
pen.WriteLine "headerText = null;"
pen.WriteLine "textColor = null;"
pen.WriteLine "fillColor = null;"
pen.WriteLine "fileLocation = null;"
pen.WriteLine "originalUnit = null;"
pen.WriteLine "headerDoc = null;"
pen.WriteLine "textLayer = null;"
pen.WriteLine "headerSaveOptions = null;"
pen.WriteLine "headerFile = null;"
pen.close()
set pen = nothing
set paper = nothing
' ERROR Trap
ProbeError()
' SPAWN Adobe With JSX
set sbatch = Server.CreateObject("WScript.Shell")
sbatch.Run locale & dbJsx, 0, FALSE
set sbatch = nothing
' ERROR Trap
ProbeError()
' SHOW Output
response.write "<html>" & vbcrlf
response.write "<body>" & vbcrlf
response.write errInfo & vbcrlf
response.write "</body>" & vbcrlf
response.write "</html>" & vbcrlf
' FREE Resources
set appName = nothing : set dbJsx = nothing : set errInfo = nothing : set height = nothing : set width = nothing
set title = nothing : set tcolor = nothing : set bcolor = nothing : set name = nothing : set txt_font = nothing
set txt_size = nothing : set txt_horizontalScale = nothing : set txt_verticalScale = nothing
set txt_translateX = nothing : set txt_translateY = nothing : set gif_colors = nothing
%>