How to detect the main color of a product by image URL by using GPT4 Vision API

Farid Movsumov
4 min readNov 8, 2023
How to build an API to extract color from product image URLs?

OpenAI published GPT4 vision API, which has amazing image analyzing capabilities that developers have been waiting for a long time.

I just made a simple prompt to extract the main color of the product, and it gives amazing results.

Let’s say you have a fashion e-commerce store where you get products from different suppliers, and color information is not structured in a standard way. You need to detect the product's color to allow your customers to filter products using the color filter on your website.

Example product color filter dropdown

By using the gpt-4-vision-preview model, you can easily achieve this goal. Let’s build a simple example using the Laravel (PHP) framework.

We will provide an output product image URL and product name, and we expect to get one of the predefined colors we have in our filter system. In some cases, the product image URL is enough to provide, but in sometimes, it is more helpful to provide the product name as it may contain some information to help detect the main color of the product.

First, let’s see what our prompt will look…

--

--