-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalchemy.php
38 lines (31 loc) · 976 Bytes
/
alchemy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require_once("common.php");
class Alchemy{
public $ini;
function __construct(){
$this->ini = parse_ini_file("api.ini",true)["alchemy"];
}
function sendUrl($url){
$key = $this->ini["key"];
$url = "http://access.alchemyapi.com/calls/url/URLGetRankedImageKeywords"
."?apikey=".$key
."&forceShowAll=1&outputMode=json"
."&url=".$url;
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
$response = curl_exec($curl);
$keywords = json_decode($response,true)["imageKeywords"];
$kw = "";
foreach($keywords as $keyword){
$kw = $kw . $keyword["text"] . ",";
}
return $kw;
}
}
if( isset($_GET["img"]) ){
$img = $_GET["img"];
$alchemy = new Alchemy();
echo $alchemy->sendUrl($img);
}