Created
March 23, 2021 01:09
-
-
Save symisc/059c9d09e6daf6f59345d8b095d65c70 to your computer and use it in GitHub Desktop.
Tag an image based on detected visual content using the PixLab API - https://pixlab.io/cmd?id=tagimg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* PixLab PHP Client which is just a single class PHP file without any dependency that you can get from Github | |
* https://github.com/symisc/pixlab-php | |
*/ | |
require_once "pixlab.php"; | |
# Tag an image based on detected visual content which mean running a CNN on top of it. | |
# https://pixlab.io/#/cmd?id=tagimg for more info. | |
# Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the sample set for more info. | |
$img = 'https://s-media-cache-ak0.pinimg.com/originals/35/d0/f6/35d0f6ee0e40306c41cfd714c625f78e.jpg'; | |
# Your PixLab API Key. Get yours from https://pixlab.io/dashboard | |
$key = 'PIXLAB_API_KEY'; | |
/* Process */ | |
$pix = new Pixlab($key); | |
if( !$pix->get('tagimg',array( | |
'img' => $img | |
)) ){ | |
echo $pix->get_error_message(); | |
die; | |
} | |
/* Grab the total number of tags */ | |
$tags = $pix->json->tags; | |
echo "Total number of tags: ".count($tags)."\n"; | |
foreach($tags as $tag){ | |
echo "Tag = ".$tag->name.", Confidence: ".$tag->confidence."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment