In company news, product announcements

Joining The PHP Parade With Our New API Client

By Team Clarifai

We’re excited to announce the immediate availability of our new official Clarifai PHP client. This has been one of our most requested libraries and we’re excited to release it!

GET IT ON GITHUB

At Clarifai, a large portion of our API Requests come through our API Clients. It’s the interface that developers most commonly use to interact with our API. That’s why we’re excited to launch Clarifai’s Official PHP client. This has been our most requested language to offer support for, and it will allow the over 5 million active PHP developers (estimate from Zend) to easily add computer vision in their applications. We’re excited to see what you build.

Getting started with the client is super easy. You can include Clarifai in your project by using the popular package manager, Composer.

Begin by installing Clarifai to your project. Simply run the following in the root directory of your project:
composer require clarifai/clarifai-php

This will add the Clarifai package to your project. Then you can make predictions accordingly:

use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Inputs\ClarifaiURLImage;
use Clarifai\DTOs\Outputs\ClarifaiOutput;
use Clarifai\DTOs\Predictions\Concept;

$client = new ClarifaiClient('YOUR_API_KEY');

$response = $client->publicModels()->generalModel()->predict(
        new ClarifaiURLImage('https://samples.clarifai.com/metro-north.jpg'))
    ->executeSync();

if ($response->isSuccessful()) {
   $output = $response->get();

    echo "Predicted concepts:\n";
    
    foreach ($output->data() as $concept) {
        echo $concept->name() . ': ' . $concept->value() . "\n";
    }
} else {
    echo "Response is not successful. Reason: \n";
    echo $response->status()->description() . "\n";
    echo $response->status()->errorDetails() . "\n";
    echo "Status code: " . $response->status()->statusCode();
}

 For more code samples you can check out our documentation. If you would like to see us launch any other clients, you can let us know here. Please send any feedback to support@clarifai.com, Happy Hacking!

Previous Next