From 7ebef2a77eda8e8740f9c3ec0916fce03df93d03 Mon Sep 17 00:00:00 2001 From: samchadwick Date: Mon, 8 Jan 2024 20:50:08 +0100 Subject: [PATCH 1/5] Create MyKeyworder.php --- api_classes/MyKeyworder.php | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 api_classes/MyKeyworder.php 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; + } +} From 116d381d5dd1110ce965e13d4f7a7923ff31ff97 Mon Sep 17 00:00:00 2001 From: samchadwick Date: Mon, 8 Jan 2024 20:52:06 +0100 Subject: [PATCH 2/5] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e0074b..06df408 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://www.mykeyworder.com/) (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://www.mykeyworder.com/) 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. From 6e0147b4cef422463867eb4d7326eda36df02724 Mon Sep 17 00:00:00 2001 From: samchadwick Date: Mon, 8 Jan 2024 20:53:04 +0100 Subject: [PATCH 3/5] Update api_types.php --- include/api_types.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 @@ Date: Mon, 8 Jan 2024 20:53:53 +0100 Subject: [PATCH 4/5] Update functions.inc.php --- include/functions.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index d722d34..fc36cb7 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -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; } @@ -84,4 +85,4 @@ function tr_createAndAssignTags($tags, $imageId) { set_tags($tag_ids, $imageId); return $return_info; -} \ No newline at end of file +} From e003a8dd79356e8ab67e07b36ebf386c9607cb86 Mon Sep 17 00:00:00 2001 From: samchadwick Date: Mon, 8 Jan 2024 20:56:23 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 06df408..ca719b4 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Generate and automatically apply tags to a bunch of image on the batch manager. ## Available APIs - [Imagga](https://imagga.com) - **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://www.mykeyworder.com/) (you'll have to register on MyKeyworder) +- **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 or [here](https://www.mykeyworder.com/) for MyKeyworder +* 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