Computer Vision - PHP Code Sample

The Computer Vision APIs are a collection of state-of-the-art image processing algorithms designed to return information based on the visual content, and to generate your ideal thumbnail. The Computer Vision APIs mainly includes analyzing an image, Generating a thumbnail and OCR.

Here is a sample of code using PHP 
to analyze an image.

You can find a testing console along with other code samples in our API reference documentation here.  

// This sample uses the Apache HTTP client from HTTP Components (
require_once 'HTTP/Request2.php';

$request = new Http_Request2('');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/json',
    'Ocp-Apim-Subscription-Key' => '{subscription key}',


$parameters = array(
    // Request parameters
    'visualFeatures' => 'Categories',
    'details' => '{string}',



// Request body

    $response = $request->send();
    echo $response->getBody();
catch (HttpException $ex)
    echo $ex;


    Feedback and Knowledge Base