Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.