3.0.1 • Published 4 years ago

@azure/cognitiveservices-imagesearch v3.0.1

Weekly downloads
373
License
MIT
Repository
github
Last release
4 years ago

An isomorphic javascript sdk for - ImageSearchClient

This package contains an isomorphic SDK for ImageSearchClient.

Currently supported environments

  • Node.js version 6.x.x or higher
  • Browser JavaScript

How to Install

npm install @azure/cognitiveservices-imagesearch

How to use

nodejs - Authentication, client creation and search images as an example written in TypeScript.

Install @azure/ms-rest-azure-js
npm install @azure/ms-rest-azure-js
Sample code

The following sample performs an image search for 'Microsoft Azure' with conditions such as the color has to be 'Monochrome', etc. To know more, refer to the Azure Documentation on Bing Image Search

const { ImageSearchClient } = require("@azure/cognitiveservices-imagesearch");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");

async function main() {
  const imageSearchKey = process.env["imageSearchKey"] || "<imageSearchKey>";
  const imageSearchEndPoint =
    process.env["imageSearchEndPoint"] || "<imageSearchEndPoint>";
  const cognitiveServiceCredentials = new CognitiveServicesCredentials(
    imageSearchKey
  );
  const client = new ImageSearchClient(cognitiveServiceCredentials, {
    endpoint: imageSearchEndPoint
  });

  const query = "Microsoft Azure";
  const options = {
    color: "Monochrome",
    count: 10,
    imageType: "Photo",
    safeSearch: "Strict"
  };
  client.images
    .search(query, options)
    .then(result => {
      console.log("The result is: ");
      console.log(result);
    })
    .catch(err => {
      console.log("An error occurred:");
      console.error(err);
    });
}

main();

browser - Authentication, client creation and search images as an example written in JavaScript.

Sample code
  • index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>@azure/cognitiveservices-imagesearch sample</title>
    <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
    <script src="node_modules/@azure/cognitiveservices-imagesearch/dist/cognitiveservices-imagesearch.js"></script>
    <script type="text/javascript">
      const imageSearchKey = "<YOUR_IMAGE_SEARCH_KEY>";
      const imageSearchEndPoint = "<YOUR_IMAGE_SEARCH_ENDPOINT>";
      const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
        inHeader: {
          "Ocp-Apim-Subscription-Key": imageSearchKey
        }
      });
      const client = new Azure.CognitiveservicesImagesearch.ImageSearchClient(
        cognitiveServiceCredentials,
        {
          endpoint: imageSearchEndPoint
        }
      );

      const query = "Microsoft Azure";
      const options = {
        color: "Monochrome",
        count: 10,
        imageType: "Photo",
        safeSearch: "Strict"
      };
      client.images
        .search(query, options)
        .then(result => {
          console.log("The result is: ");
          console.log(result);
        })
        .catch(err => {
          console.log("An error occurred:");
          console.error(err);
        });
    </script>
  </head>
  <body></body>
</html>

Related projects

Impressions

3.0.1

4 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

0.1.0

6 years ago

1.0.0

6 years ago