【问题标题】:API integration with Photoshop [closed]API与Photoshop集成[关闭]
【发布时间】:2014-12-28 16:18:35
【问题描述】:

我对通过 Javascript 编写 Photoshop 脚本有一个基本概念。

我想在我的 Photoshop 脚本中使用来自 http://www.wunderground.com (Api) 的数据。

但不知道如何请求(访问)这些数据。

【问题讨论】:

  • 您自己尝试过吗?

标签: javascript api photoshop wunderground


【解决方案1】:

我可以做那种事情,但我不确定它有多笨重 - 可能有更简单的方法我不知道 - 所以我们会看看是否有其他人想出更好的东西。

首先,找到你的 PHP 所在的位置,如下所示:

which php
/usr/local/bin/php

所以我看到我的在/usr/local/bin/php。我的 PHP 脚本的第一行需要它。

现在制作一个访问 Wunderground API 的独立 PHP 脚本。我没有密钥,所以我实际上并没有调用他们的 API,而是注释掉了调用,然后伪造了结果。所以我把它保存为/Users/Mark/tmp/wunderground.php

#!/usr/local/bin/php
<?php
  // $json_string = file_get_contents("http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json");
  // $parsed_json = json_decode($json_string);
  // $location = $parsed_json->{'location'}->{'city'};
  // $temp_f = $parsed_json->{'current_observation'}->{'temp_f'};
  // echo "Current temperature in ${location} is: ${temp_f}\n";
  echo "Current temperature in 36";
?>

我像这样使那个可执行文件:

chmod +x /Users/Mark/tmp/wunderground.php

然后像这样运行它:

/Users/Mark/tmp/wunderground.php
Current temperature is 36

这一步必须在你做任何其他事情之前起作用,所以我在这里单独测试它......看起来不错!

现在我写了一个 Photoshop Actionscript/Javascript 东西并将它保存为&lt;Photoshop&gt;/Presets/Scripts/Test.jsx

alert("Hello world!")
app.system("/Users/Mark/tmp/wunderground.php > /Users/Mark/result.txt")
var w = new File("/Users/Mark/result.txt");
w.open('r');
var str = "";
while(!w.eof)
   str += w.readln();
w.close();   
alert(str);

您会看到它在第二行执行PHP 脚本并将结果保存在一个文件中,然后我读取该文件并将其内容显示在alert() 中。

所以,我在编辑脚本后重新启动了 Photoshop(它只在启动时解析它们),然后我在 Photoshop 中转到 File-&gt;Scripts 并选择 Test.jsx

这是它的外观:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 2016-01-22
    • 2018-08-15
    • 2016-10-26
    • 1970-01-01
    • 2011-01-27
    • 2011-08-07
    相关资源
    最近更新 更多