How to extract colors from your images with Uploadcare

Step 1. Sign up for an Uploadcare account. Create your first project from the workpace.

create project screenshot Create new project

Step 2. Start uploading your images.

small party on the roof Here’s our test image.

All transformations at Uploadcare are done via CDN image operations. Once an image is uploaded, you receive a CDN link with its own unique identifier (UUID). The link looks like this:

https://ucarecdn.com/9c71f68a-3e48-4c89-8796-8e4730dab793/party.jpeg

Where:

  • 9c71f68a-3e48-4c89-8796-8e4730dab793 — your unique file identifier (UUID).
  • party.jpeg — the filename (it’s optional, you can remove it)

Step 3. Implement image transformations by URL API.

To make an API request, simply add the necessary parameters to the link. To extract colors from a photo, you need to add the parameters preview and main colors. Also, you can use the number of colors parameter if you need it.

After adding all the needed parameters, the link will look something like this:

https://ucarecdn.com/9c71f68a-3e48-4c89-8796-8e4730dab793/-/preview/-/main_colors/3/

Preview is the default operation for all image transformations. /-/ is the mandatory delimiter that tells operations from one another and other path components.

If everything is right, it will return a JSON containing the RGB values of the main colors found in the image:

{
  "id":"/9c71f68a-3e48-4c89-8796-8e4730dab793/-/preview/",
  "original":{
    "id":"9c71f68a-3e48-4c89-8796-8e4730dab793",
    "color_mode":"RGB",
    "orientation":null,
    "format":"JPEG",
    "sequence":false,
    "height":1253,
    "width":1880,
    "geo_location":null,
    "datetime_original":null,
    "dpi":[
      72,
      72
    ]
  },
  "width":1880,
  "height":1253,
  "main_colors":[
    [65, 126, 156],
    [38, 36, 32],
    [199, 170, 154]
  ]
}
color recognition in actionThe Color Recognition feature extracted the three main colors from the photo.

That’s it! Now you can apply this feature to your own business processes and build different solutions around it.

Final thoughts

Color Recognition is a part of the Image Intelligence feature set, which also includes AI-based tools for Object and Face Recognition. All three features allow you to extract valuable insights from any photo and use them to organize large databases of images, moderate uploaded content, filter content, and much more.

If you're interested in automating your image handling to the max, you can read our docs to learn more or jump right into hands-on exploration.

Build file handling in minutesStart for free

Ready to get started?

Join developers who use Uploadcare to build file handling quickly and reliably.

Sign up for free