Javascript を介した Photoshop スクリプト作成の基本的な考え方があります。
Photoshop スクリプトでhttp://www.wunderground.com (Api) のデータを使用したいと考えています。
しかし、これらのデータを要求 (アクセス) する方法がわかりません。
Javascript を介した Photoshop スクリプト作成の基本的な考え方があります。
Photoshop スクリプトでhttp://www.wunderground.com (Api) のデータを使用したいと考えています。
しかし、これらのデータを要求 (アクセス) する方法がわかりません。
私はそのようなことを行うことができますが、それがどれほど不格好かはわかりません.もっと簡単な方法があるかもしれません.
まず、次のように、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のことを書いて、それを<Photoshop>/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);
2行目でスクリプトを実行しPHP
、結果をファイルに保存し、その内容を読み込んでalert()
.
そのため、スクリプトを編集してから Photoshop を再起動し (スクリプトは起動時にのみ解析されます)、Photoshop に移動してFile->Scripts
選択します。Test.jsx
これがどのように見えるかです: