The Developer's Notes - Free Bonus
Learn new methods, tips and tricks from our lead developer

Learn More
Learn more about The Developer's Notes

Free Bonus
Run Adobe Photoshop CS2 through a web page!

Order Today
Get this amazing title via Windows™ based CD-ROM while its available!








You can run Adobe Photoshop CS2 from a web page -- without logging in!

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. Until now!
The Developer's Notes
FREE downloadable electronic version.
.:: The Developer's Notes ::.
 
Don't forget to see the The Developer's Notes where you can learn more tips and tricks!

With Adobe Photoshop CS2 installed on a Windows Server 2003 web server, you CAN use the power of Photoshop CS2 to create images and perform other tasks by merely accessing a regular ASP web page with a web browser. You don't need to run the CMD.EXE in your code and you don't need to create any .BAT files either.

The big question that you may have is...how can you do something like accept parameters used to create an image, pass those to your ASP page and in turn, pass that to Adobe Photoshop CS2 so that it creates the image? Although tedious to initially setup, the solution is simple...and is largely possible due to JSX importing that you can do with Adobe Photoshop CS2 (you configure a JSX file with parameters and commands similar to Javascript which Adobe Photoshop CS2 completes).

Overview
  1. [STEP 1] Set up the web server and then set up some very simple ASP pages with code in them (such as snippets below) so you can see everything working.
  2. [STEP 2] Create an ASP page with a form in it. The form prompts for text that you want to have appear in the image.
  3. [STEP 3] Create an ASP page that accepts the form data. This ASP page will also create the JSX file. This ASP page will also invoke Adobe Photoshop CS2 and the JSX file will be read by Adobe Photoshop CS2 and the image will be created.
STEP 1
SERVER STEPS:
  1. Grant Local Activation permission for the COM Server application with CLSID {A1F4E726-8CF1-11D1-BF92-0060081ED811} to the user NT AUTHORITY\NETWORK SERVICE SID (S-1-5-20), by giving the Internet Guest User Account (IUSR_...) Launch and Local Activation permissions.
  2. The Windows Image Activation Service must be started.
  3. The DCOM Server Process Launcher service must be started.
  4. User accounts (IUSR, System, etc) have permissions to the destination folder where the image is to be created at. Make sure the Internet Guest User Account (IUSR_...) has permissions to write to the folder; if writing is not allowed, the image will not get created. Here is the permissions that are typically used: Modify, Read & Execute, List Folder Contents, Read, Write. You may need to modify other accounts so they have Write permissions so that files can be created. NOTE: If you have an Active Directory account and use it to login to get to the script, your account may also need to be modified or have a policy created to handle it.
  5. Be sure to attach those accounts to the application folders as well (hopefully your install is not strung across multiple drives).
  6. Add the network service account access to c:\document and settings\default user (this is a hidden folder).
  7. Add the network service account access to c:\windows\debug\usermode.
  8. UNINSTALL Extendscript Toolkit from the web server (typically located here: \Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit). This helps ensure that the toolkit will not be triggered when the ASP web page is calling a JSX file. For unknown reasons if the ASP/JSX file is moved on the web server and called from the new location the Extendscript Toolkit is spawned instead of Photoshop CS2(even though MIME association for JSX is set to Photoshop CS2...however, the MIME association is recognized if the JSX is double-clicked locally). The same applies if a JSX file is edited with the Extendscript Toolkit and saved locally on the web server (the edit action that is accessible by right-clicking on the file and choosing "Edit"). ALWAYS open JSX files with Notepad to be safe. NOTE: You may have to upgrade the ToolKit to get the uninstall option.
  9. Restart the web server. Depending on your web server you may have to go as far as physically powering it down and back on again.
  10. Explicitly associate JSX file extensions to open with Photoshop CS2.
  11. Examine security policies to minimize granting too much power to anonymous web surfers accessing your web server. For example, while you may have to temporarily expand permissions to get everything working which you then taper back based on your requirements, the "Everyone Group" should never have "Full Control" anywhere.
TEST CODE SNIPPET:
This code snippet is helpful if you are in the testing phase of trying to create a file on the web server using a similar process as how an image file would be created on the web server with Photoshop CS2. If this code snippet does not work, you have a permissions issue to deal with.
-- BEGIN TEST CODE SNIPPET
<%
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
%>
-- END TEST CODE SNIPPET

PHOTOSHOP CS2 CODE SNIPPET:
This code snippet is helpful when you've reached the point of actually having Photoshop CS2 run on the web server as a network service to create an image and having the process spawned through an ASP web page on the web server. Make sure your JSX is correct and has no errors (accomplished by double-clicking on the JSX file while you are locally at the web server; double-clicking should spawn Photoshop CS2 to execute the JSX; the JSX then creates the image and saves it on the web server).
The Photoshop CS2 application will stay active on the web server as a Network Service after it is completed with creating the image. Typically this is not an issue considering it takes between 30 seconds to 1 minute for Photoshop CS2 to load...so most likely you will not want to repeatedly open and close the application and degrade server performance each time an image is created. Since Photoshop CS2 loads as a Network Service you will not see the application open on the Task Bar. You can only see the Photoshop CS2 process by viewing the Process tab of Task Manager on the web server.

-- BEGIN PHOTOSHOP CS2 CODE SNIPPET
<%
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
%>
-- END PHOTOSHOP CS2 CODE SNIPPET

CLOSING DOWN PHOTOSHOP CS2 VIA A ASP WEB PAGE:
You can close down the Photoshop CS2 Network Service process through an ASP web page if you want and can be accomplished using the ASP code snippet below (since there is no way I am aware of, as of this writing, to signal Photoshop CS2 to close itself down through JSX code):

-- BEGIN CLOSE SNIPPET
<%
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
%>
-- END CLOSE SNIPPET

STEP 2
Now that it has been established that Adobe Photoshop CS2 can be invoked from an ASP web page and that it can read and complete the actions in a simple JSX file you have written (a JSX file is just a text file with the JSX extension), it's time to add on what can be done. In this case, we'll prompt for some text so that the image that will be created will have some custom text inside of it.

<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>

STEP 3
Now it's time for the meat and potatoes. This ASP page (which should be the name of the ASP file you point to in the form (above)) will take the form data, create or modify the .JSX file and spawn Adobe Photoshop CS2 so that it can read the .JSX file and create the image on the web server. Ready for the code? Here it is...

<%
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"
dbJsx = "adobe_jsx.jsx"
errInfo = ""
height = 65
width = 490
title = "This is a test"
tcolor = "FFFFFF"
bcolor = "000000"
name = "test"
txt_font = "Verdana"
txt_size = 25
txt_horizontalScale = 100
txt_verticalScale = 115
txt_translateX = -35
txt_translateY = 37
gif_colors = 16
' Name of this application
' Adobe JSX File Containing Commands for Photoshop CS2
' Catch Error Output From Execution
' Default height of image
' Default width of image
' Default title of image
' Default text color of image
' Default background color of image
' Default filename of image
' Default text font type to use in image
' Default font size
' Default font horizontal scale
' Default font vertical scale
' Default font X translation
' Default font Y translation
' 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 "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;"
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
%>

MORE TIPS AND TRICKS
This is just the tip of the iceburg for advanced and in some cases "the secret arts" of what you can do with web sites. Check out The Developer's Notes today!

This Step-by-Step guide for educational purposes only was first made available online 12-23-2006.

Main Page ©CommerceWeaver Pro™ & Web Site ©2004 All Rights Reserved. Optimized for IE 6x. Terms of Service.