Skip to content

Instantly share code, notes, and snippets.

@nadavkav
Created May 14, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadavkav/f43adac450c4b04190f110287d183e93 to your computer and use it in GitHub Desktop.
Save nadavkav/f43adac450c4b04190f110287d183e93 to your computer and use it in GitHub Desktop.
<?php
// Use clarifai web service to tag iamges
require('../../config.php');
require_once($CFG->dirroot . "/lib/filelib.php");
$curl = new curl();
//$c->setopt(array('CURLOPT_TIMEOUT' => 3, 'CURLOPT_CONNECTTIMEOUT' => 3));
$image_to_tag = optional_param('imageurl', null , PARAM_URL );
if ($image_to_tag) {
$image_url = $image_to_tag;
} else {
$image_url = new moodle_url('https://samples.clarifai.com/metro-north.jpg');
}
// https://developer.clarifai.com
// My First Application
// client_id = XXX
// client_secret = YYY
$accesstoken = 'ZZZ';
$ws_url = new moodle_url('https://api.clarifai.com/v1/tag?url='.$image_url.'&access_token='.$accesstoken);
$response = $curl->get($ws_url);
if (!$response || $curl->info['http_code'] != 200 || !empty($curl->errorno)) {
throw new moodle_exception('errorinvalidwsurl', 'tagimage');
}
$image_tags = json_decode($response);
print_object($image_tags->results[0]->result->tag->classes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment