Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ Generate and automatically apply tags to a bunch of image on the batch manager.

## Available APIs
- [Imagga](https://imagga.com)
- **New** [Microsft Azure](https://azure.microsoft.com/fr-fr/services/cognitive-services/computer-vision/) (you'll have to create an application on Azure)
- **New** [Microsoft Azure](https://azure.microsoft.com/fr-fr/services/cognitive-services/computer-vision/) (you'll have to create an application on Azure)
- **New** [MyKeyworder](https://mykeyworder.com/api) (you'll have to register on MyKeyworder)

## Usage
* Install the plugin on your Piwigo
* Create an Imagga Account on https://imagga.com/auth/signup (or [here](https://azure.microsoft.com/fr-fr/free/cognitive-services/) for Microsoft Azure)
* Create an Imagga Account on https://imagga.com/auth/signup or [here](https://azure.microsoft.com/fr-fr/free/cognitive-services/) for Microsoft Azure or [here](https://mykeyworder.com/api) for MyKeyworder
* Enter your api token and api secret on the plugin configuration page
* Go to an image modification page and click on the little robot next to the tags input
* Generate tags, select the ones you want and apply them

### Warning
As this plugin use an external API, we cannot assure you that your data will not be used or sold. I recommend you to check the data policy of each external API you use with this plugin.
As this plugin use an external API, we cannot assure you that your data will not be used or sold. I recommend you to check the data policy of each external API you use with this plugin.
64 changes: 64 additions & 0 deletions api_classes/MyKeyworder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

class MyKeyworder extends API {

function getInfo() : array
{
return [
"icon" => 'https://mykeyworder.com/img/logo.png',
"site" => 'https://mykeyworder.com/',
"info" => `
MyKeyworder is a keywording tool for photographers. The image recognition API provides programmatic access to the MyKeyworder Image Recognition service for automatically keywording larger volumes of images.
`
];
}

function getConfParams() : array
{
return [
'USER' => 'API Username',
'USER_PASSWORD'=> 'API Key'
];
}

function generateTags($conf, $params) : array
{

if (isset($_SERVER['HTTPS'])){
$file_path = "https://".$_SERVER['HTTP_HOST'].ltrim($this->getFileName($params['imageId']), '.');
} else {
$file_path = "http://".$_SERVER['HTTP_HOST'].ltrim($this->getFileName($params['imageId']), '.');
}

if (!(isset($conf['USER']) && isset($conf['USER_PASSWORD'])))
throw new Exception('API parameters are not set');

$api_credentials = array(
'key' => $conf['USER'],
'secret' => $conf['USER_PASSWORD']
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://mykeyworder.com/api/v1/analyze?url='.urlencode($file_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_USERPWD, $api_credentials['key'].':'.$api_credentials['secret']);

$response = curl_exec($ch);
curl_close($ch);

$json_response = json_decode($response);

$tags = [];

if(isset($json_response->keywords)){
foreach ($json_response->keywords as $tagObject)
{
$tagObjectArray = json_decode(json_encode($tagObject), true);
array_push($tags, $tagObjectArray);
}
}

return $tags;
}
}
4 changes: 2 additions & 2 deletions include/api_types.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('TR_API_LIST', ['Imagga', 'Azure']);
define('TR_API_LIST', ['Imagga', 'Azure','MyKeyworder']);

abstract class API
{
Expand Down Expand Up @@ -44,4 +44,4 @@ function getFileName($imageId) {
// Include all the API
foreach (TR_API_LIST as $apiName) {
include_once(TR_PATH.'api_classes/'.$apiName.'.php');
}
}
3 changes: 2 additions & 1 deletion include/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function tr_getAPI($api) : API {
$ret = new Imagga();

if ($api == 'Azure') $ret = new Azure();
if ($api == 'MyKeyworder') $ret = new MyKeyworder();

return $ret;
}
Expand Down Expand Up @@ -84,4 +85,4 @@ function tr_createAndAssignTags($tags, $imageId) {
set_tags($tag_ids, $imageId);

return $return_info;
}
}