top of page
Detect Image Labels

Detect Image Labels

Use Google’s vision NPM module to detect an image’s labels.

Intermediate.png

Advanced

3K

Published:

March 31, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example we create a page where you can upload any image. The uploaded image is sent to Google vision API in order to detect labels that are associated with this image.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Backend

vision.jsw - imports the vision NPM module and exports a getLabels function which:

  1. Uses secrets manager API to get credentials to Google.

  2. Creates a URL for the uploaded image.

  3. Sends this URL to Google vision API and returns the unique labels it detected.

Notes:

  • we are also using lodash NPM module to simplify the code for returning unique labels.

  • The secret key used in this example will not be available under your account. In order to make the example work please go to https://cloud.google.com/vision/docs/auth in order to get your own secret key and place it in the secrets manager.

​​

Page Elements

In our site we added the following page elements:

  • Upload & Submit buttons - let the user upload an image.

  • Image - displays the uploaded image.

  • Repeater - displays the labels detected for the uploaded image.

​​

Code

In $w.onReady we added a onAfterSave event handler function that runs after the image was uploaded. The function does the following:

  • Call the getLabels backend function to get the image’s labels.

  • Create an array called imageLabels that holds these labels alongside a unique id for each label.

  • Populates the repeater with the imageLabels array.

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Hide and Show an Image

Hide and Show an Image

Show and hide an image according to the clicked button.

Intermediate.png

Beginner

SendGrid npm Integration

SendGrid npm Integration

Use SendGrid’s npm module to send emails from your site

Intermediate.png

Intermediate

Twilio Integration

Twilio Integration

Integrate with Twilio to make voice calls and send SMS messages

Intermediate.png

Advanced

Anchor 2
bottom of page