Upload image with Photoshop scripting
Is that possible to 开发者_开发百科upload an image from Photoshop (for example, an open image exported to jpeg) to some web place - REST service, FTP etc by using scripting features of Photoshop? For example - I have an image open in Photoshop and then execute some special script that sends an exported version of it to some place over the web. I saw something like this but it uses an automatically generated batch file that executes ftp command on Windows. I would like to use something more beautiful if it's possible. Or may be there are some info to know how to make a simple plugin for just this task. Thanks.
The Photoshop API exposes a socket object. You can use it like this
function sendDataToServer(data) {
var socket = new Socket(),
port = 80,
domain = "www.example.com",
page = "/path/to/file.php",
bin;
if(socket.open(domain + ":" + port,"binary")) {
socket.write("GET http://" + domain + page + "?data=" + data + " HTTP/1.0\n\n");
bin = socket.read(9999999);
alert(bin);
socket.close();
}
}
This will return the servers response plus the headers for the request. You can read the file through using a method like this:
function getLine(html){
var line = "", i = 0;
for (; html.charCodeAt(i) != 10; i++){ // finding line end
line += html[i] ;
}
return line;
}
Also this method will strip the headers using the getLine
method:
function removeHeaders(binary){
var bContinue = true, // flag for finding end of header
line = "",
nFirst = 0,
count = 0;
while (bContinue) {
line = getLine(binary) ; // each header line
bContinue = line.length >= 2 ; // blank header == end of header
nFirst = line.length + 1 ;
binary = binary.substr(nFirst) ;
}
return binary;
}
The standard way to upload files to REST web service is: 1. Use POST with Content-Type: application/octet-stream including the image stream in the body. 2. Use the "SLUG" header when POSTing to supply the image file name.
I don't know what kind of API PhotoShop exposes, but I guess there is an API to read the image stream, So using this API you can prepare the required POST request and adding the image to your server :-)
Hope that I helped, Shay
The API's within photoshop do not allow for network access. They just control photoshop and are limited to user actions you can do within Photoshop.
I would suggest using Automator or another external scripting language to post-process the output of photoshop.
If the Photoshop API doesn't support network access, you could try loading a Flash/Flex file from the script, and do then do the upload in the swf.
Probably with JavaScript in photoshop:
http://www.adobe.com/devnet/bridge/pdfs/javascript_tools_guide_cs3.pdf
精彩评论