diff --git a/README.md b/README.md index 8e0074b..ca719b4 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +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. diff --git a/api_classes/MyKeyworder.php b/api_classes/MyKeyworder.php new file mode 100644 index 0000000..bf240d3 --- /dev/null +++ b/api_classes/MyKeyworder.php @@ -0,0 +1,64 @@ + '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; + } +} diff --git a/include/api_types.php b/include/api_types.php index 30ba281..19654b8 100644 --- a/include/api_types.php +++ b/include/api_types.php @@ -1,6 +1,6 @@