使用Photoshop脚本上传图像

Ser*_*rov 3 photoshop rest scripting plugins

可以通过使用Photoshop的脚本功能将Photoshop中的图像(例如,导出到jpeg的打开图像)上传到某个Web位置 - REST服务,FTP等吗?例如 - 我在Photoshop中打开了一个图像,然后执行一些特殊的脚本,将其导出的版本发送到Web上的某个位置.我看到这样的东西,但它使用自动生成的批处理文件,在Windows上执行ftp命令.如果有可能的话,我想用更美的东西.或者可能有一些信息知道如何为这个任务制作一个简单的插件.谢谢.

Hug*_*ade 7

Photoshop API公开套接字对象.你可以像这样使用它

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();
    }

}
Run Code Online (Sandbox Code Playgroud)

这将返回服务器响应以及请求的标头.您可以使用以下方法读取文件:

function getLine(html){
    var line = "", i = 0;
    for (; html.charCodeAt(i) != 10; i++){ // finding line end
        line += html[i] ;
    }
    return line;
}
Run Code Online (Sandbox Code Playgroud)

此方法还将使用以下getLine方法剥离标头:

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;
}
Run Code Online (Sandbox Code Playgroud)