title: PHP - how to extract text from image using Google Cloud Vision
body: <pre><code>namespace Google\Cloud\Samples\Vision;    
  
  require_once('../vendor/autoload.php');
  
      use Google\Cloud\Vision\VisionClient;
  
      $vision = new VisionClient([
          'projectId' =&gt; 'xxx',
          'keyFilePath' =&gt; 'xxx.json'
      ]);
  
  
  
  
      use Google\Cloud\Vision\V1\ImageAnnotatorClient;
  
  
      function detect_text($path)
      {
          $imageAnnotator = new ImageAnnotatorClient();
  
          # annotate the image
          $image = file_get_contents($path);
          $response = $imageAnnotator-&gt;textDetection($image);
          $texts = $response-&gt;getTextAnnotations();
  
          printf('%d texts found:' . PHP_EOL, count($texts));
          foreach ($texts as $text) {
              print($text-&gt;getDescription() . PHP_EOL);
  
              # get bounds
              $vertices = $text-&gt;getBoundingPoly()-&gt;getVertices();
              $bounds = [];
              foreach ($vertices as $vertex) {
                  $bounds[] = sprintf('(%d,%d)', $vertex-&gt;getX(), $vertex-&gt;getY());
              }
              print('Bounds: ' . join(', ',$bounds) . PHP_EOL);
          }
  
          $imageAnnotator-&gt;close();
      }
  
      echo detect_text('read.png');
  </code></pre>
  
  <p>Installed the SDK and PHP Package and I'm getting error 500 no matter what I do!</p>
  
  <p>How can I get this running?</p>
  
  <p>This is the error I get:</p>
  
  <pre><code>[01-Feb-2020 19:09:48 UTC] PHP Warning:  file_exists(): open_basedir restriction in effect. File(C:\Windows\system32\config\systemprofile\AppData\Roaming\gcloud/application_default_credentials.json) is not within the allowed path(s): (C:/Inetpub/vhosts/xxxxxxx.com\;C:\Windows\Temp\) in C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\auth\src\CredentialsLoader.php on line 100
  [01-Feb-2020 19:09:50 UTC] PHP Fatal error:  Uncaught DomainException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\auth\src\ApplicationDefaultCredentials.php:168
  Stack trace:
  #0 C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\gax\src\CredentialsWrapper.php(197): Google\Auth\ApplicationDefaultCredentials::getCredentials(Array, Object(Google\Auth\HttpHandler\Guzzle6HttpHandler), NULL, NULL)
  #1 C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\gax\src\CredentialsWrapper.php(114): Google\ApiCore\CredentialsWrapper::buildApplicationDefaultCredentials(Array, Object(Google\Auth\HttpHandler\Guzzle6HttpHandler))
  #2 C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\gax\src\GapicClientTrait.php(339): Google\ApiCore\CredentialsWrapper::build(Array)
  #3 C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\gax\src\GapicClientTrait.php(321): Google\Cloud\Vision\V1\Gapic\ImageAnnotatorGapicClient-&gt;createCredentialsWrapper(NULL, in C:\Inetpub\vhosts\xxxxxxx.com\vendor\google\gax\src\CredentialsWrapper.php on line 200
  </code></pre>
  
  <p>I have done everything exactly how their documentation said to: <a href="https://cloud.google.com/vision/docs/setup" rel="nofollow noreferrer">https://cloud.google.com/vision/docs/setup</a> what am I suppose to do now?</p>