Free plan

Replace color

Change one colour in a picture into another colour
POST
/v1/images/replace-color
Red to blue
Original
OriginalRed to blue

About this tool

This tool finds every part of a picture that is close to one colour and changes it to another colour, or makes it see-through. You pick the colour to replace, or click a spot in the picture to copy it. A tolerance setting says how close a colour must be, and a softness setting blends the edges. You can also keep the light and dark of the original so folds and shadows still show.
For example, you turn a red shirt in a photo into a blue shirt, or change the colour of a logo to match your brand.

How to use it

  1. Choose this tool.
  2. Add your picture with Upload or drag and drop.
  3. Choose the colour to replace and the new colour.
  4. Adjust the tolerance and softness, and tick keep shading if you want the folds to stay.
  5. Press Generate, then download the picture.

What you get back

You get a new picture with the colour changed. Your original file is not changed.
GOOD TO KNOW
A picture where no pixel is close enough is refused (400). Counts as one image per picture.
TEST IT LIVE

Try Replace color in the Studio

One click opens the Studio with this tool already selected. Add your file and see the result in seconds.
Open in the Studio
Family
Images
Plan
Free
Method
POST
Endpoint
/v1/images/replace-color
Tool ID
images.replace-color
Authentication
API key
Accepts
JPEG, PNG, WEBP, GIF, AVIF, TIFF +15 more
Background jobs
Yes
Usage group
Image
For developers

Use it from your code

cURL

curl -X POST "https://app.h2i.davixlabs.io/v1/images/replace-color" \
  -H "X-Api-Key: $DAVIX_H2I_API_KEY" \
  -F 'images=@photo.jpg' \
  -F 'from=#1a73e8' \
  -F 'sample=120,80' \
  -F 'to=#1a73e8'

Node.js

const { DavixH2I } = require('@davixlabs/h2i-sdk');

const h2i = new DavixH2I({ apiKey: process.env.DAVIX_H2I_API_KEY, baseUrl: process.env.DAVIX_H2I_URL });
const result = await h2i.images.replaceColor({
    "images": 'photo.jpg',
    "from": "#1a73e8",
    "sample": "120,80",
    "to": "#1a73e8"
  });
console.log(result.data, result.requestId);

PHP

<?php
require 'vendor/autoload.php';

$h2i = new \Davix\H2I\Client(['apiKey' => getenv('DAVIX_H2I_API_KEY'), 'baseUrl' => getenv('DAVIX_H2I_URL')]);
$result = $h2i->images()->replaceColor([
    'images' => 'photo.jpg',
    'from' => '#1a73e8',
    'sample' => '120,80',
    'to' => '#1a73e8',
]);
echo $result->requestId;
FAQ

Frequently asked questions

Turn every pixel close to one colour into another colour, or into transparency, with a tolerance and a soft edge; optionally keep the light and dark of the original so a red shirt becomes a blue shirt with its folds.

Replace color accepts JPEG, PNG, WEBP, GIF, AVIF, TIFF, SVG, SVGZ, BMP, ICO, APNG, PNM and 9 more. You can send several files in one request.

Replace color is included in every plan, including Free. Each run uses credits from your monthly allowance.

Send a POST request to /v1/images/replace-color with your API key in the X-Api-Key header. Official SDKs for Node.js, Python, PHP, Go, Java, .NET and Ruby do the same for you, and the code box on this page shows ready-to-copy examples. For large work it can also run as a background job, so your request returns straight away.