Dominant colour palette of an image (hex, RGB, share)
Extracts the dominant colours of an image as hex and RGB, with each colour's share of the image.
Request
Upload the image in the file field (max 25 MB). Instead of a file you can send JSON: {"url": "https://…"} for a public image URL, or {"base64": "…"} — the options below then go in the same JSON object.
Parameters and body structure are inherited from this endpoint's definition. Changes here only apply to this test run.
1curl --request POST \
2 --url https://image-tools.p.apihiver.com/v1/colors \
3 --header 'Accept: application/json' \
4 --header 'X-API-Key: YOUR_API_KEY' \
5 --header 'content-type: multipart/form-data' \
6 --form file=@file.bin \
7 --form count=6Dominant colour palette of an image (hex, RGB, share): Image Tools API reference
Extracts the dominant colours of an image as hex and RGB, with each colour's share of the image. This endpoint is part of the Image Tools API: Resize, crop, convert, rotate and compress images, add text watermarks, extract colour palettes and make placeholder images.
Dominant colour palette of an image (hex, RGB, share): example requests in every language
POST /v1/colors in Shell (cURL)
curl --request POST \
--url https://image-tools.p.apihiver.com/v1/colors \
--header 'Accept: application/json' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'content-type: multipart/form-data' \
--form [email protected] \
--form count=6POST /v1/colors in Shell (HTTPie)
echo '-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="count"
6
-----011000010111000001101001--
' | \
http POST https://image-tools.p.apihiver.com/v1/colors \
Accept:application/json \
X-API-Key:YOUR_API_KEY \
content-type:'multipart/form-data; boundary=---011000010111000001101001'POST /v1/colors in Shell (Wget)
wget --quiet \
--method POST \
--header 'Accept: application/json' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file.bin"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="count"\r\n\r\n6\r\n-----011000010111000001101001--\r\n' \
--output-document \
- https://image-tools.p.apihiver.com/v1/colorsPOST /v1/colors in Node.js (http)
const http = require('https');
const options = {
method: 'POST',
hostname: 'image-tools.p.apihiver.com',
port: null,
path: '/v1/colors',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on('data', function (chunk) {
chunks.push(chunk);
});
res.on('end', function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file.bin"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="count"\r\n\r\n6\r\n-----011000010111000001101001--\r\n');
req.end();POST /v1/colors in Node.js (Request)
const fs = require('fs');
const request = require('request');
const options = {
method: 'POST',
url: 'https://image-tools.p.apihiver.com/v1/colors',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
},
formData: {
file: {
value: fs.createReadStream('file.bin'),
options: {filename: 'file.bin', contentType: 'multipart/form-data'}
},
count: '6'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});POST /v1/colors in Node.js (Unirest)
const fs = require('fs');
const unirest = require('unirest');
const req = unirest('POST', 'https://image-tools.p.apihiver.com/v1/colors');
req.headers({
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
});
req.multipart([
{
body: fs.createReadStream('file.bin'),
'content-type': 'multipart/form-data'
},
{
body: '6'
}
]);
req.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.body);
});POST /v1/colors in Node.js (Axios)
const axios = require('axios').default;
const options = {
method: 'POST',
url: 'https://image-tools.p.apihiver.com/v1/colors',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
},
data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file.bin"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="count"\r\n\r\n6\r\n-----011000010111000001101001--\r\n'
};
try {
const { data } = await axios.request(options);
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/colors in Node.js (Fetch)
const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');
const formData = new FormData();
formData.append('file', fs.createReadStream('file.bin'));
formData.append('count', '6');
const url = 'https://image-tools.p.apihiver.com/v1/colors';
const options = {
method: 'POST',
headers: {Accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY'}
};
options.body = formData;
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/colors in JavaScript (XMLHttpRequest)
const data = new FormData();
data.append('file', 'file.bin');
data.append('count', '6');
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener('readystatechange', function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open('POST', 'https://image-tools.p.apihiver.com/v1/colors');
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('X-API-Key', 'YOUR_API_KEY');
xhr.send(data);POST /v1/colors in JavaScript (Axios)
import axios from 'axios';
const form = new FormData();
form.append('file', 'file.bin');
form.append('count', '6');
const options = {
method: 'POST',
url: 'https://image-tools.p.apihiver.com/v1/colors',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
},
data: '[form]'
};
try {
const { data } = await axios.request(options);
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/colors in JavaScript (Fetch)
const url = 'https://image-tools.p.apihiver.com/v1/colors';
const form = new FormData();
form.append('file', 'file.bin');
form.append('count', '6');
const options = {
method: 'POST',
headers: {Accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY'}
};
options.body = form;
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/colors in JavaScript (jQuery)
const form = new FormData();
form.append('file', 'file.bin');
form.append('count', '6');
const settings = {
async: true,
crossDomain: true,
url: 'https://image-tools.p.apihiver.com/v1/colors',
method: 'POST',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
processData: false,
contentType: false,
mimeType: 'multipart/form-data',
data: form
};
$.ajax(settings).done(function (response) {
console.log(response);
});POST /v1/colors in Python (http.client)
import http.client
conn = http.client.HTTPSConnection("image-tools.p.apihiver.com")
payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n"
headers = {
'Accept': "application/json",
'X-API-Key': "YOUR_API_KEY",
'content-type': "multipart/form-data; boundary=---011000010111000001101001"
}
conn.request("POST", "/v1/colors", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))POST /v1/colors in Python (Requests)
import requests
url = "https://image-tools.p.apihiver.com/v1/colors"
files = { "file": "open('file.bin', 'rb')" }
payload = { "count": "6" }
headers = {
"Accept": "application/json",
"X-API-Key": "YOUR_API_KEY"
}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.json())POST /v1/colors in PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://image-tools.p.apihiver.com/v1/colors",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n",
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"X-API-Key: YOUR_API_KEY",
"content-type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}POST /v1/colors in PHP (Guzzle)
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://image-tools.p.apihiver.com/v1/colors', [
'multipart' => [
[
'name' => 'file',
'filename' => 'file.bin',
'contents' => null,
'headers' => [
'Content-Type' => 'multipart/form-data'
]
],
[
'name' => 'count',
'contents' => '6'
]
]
'headers' => [
'Accept' => 'application/json',
'X-API-Key' => 'YOUR_API_KEY',
],
]);
echo $response->getBody();POST /v1/colors in PHP (PECL HTTP v1)
<?php
$request = new HttpRequest();
$request->setUrl('https://image-tools.p.apihiver.com/v1/colors');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders([
'Accept' => 'application/json',
'X-API-Key' => 'YOUR_API_KEY',
'content-type' => 'multipart/form-data; boundary=---011000010111000001101001'
]);
$request->setBody('-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="count"
6
-----011000010111000001101001--
');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}POST /v1/colors in PHP (PECL HTTP v2)
<?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->addForm([
'count' => '6'
], [
[
'name' => 'file',
'type' => 'multipart/form-data',
'file' => 'file.bin',
'data' => null
]
]);
$request->setRequestUrl('https://image-tools.p.apihiver.com/v1/colors');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'Accept' => 'application/json',
'X-API-Key' => 'YOUR_API_KEY'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();POST /v1/colors in Java (AsyncHttp)
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("POST", "https://image-tools.p.apihiver.com/v1/colors")
.setHeader("Accept", "application/json")
.setHeader("X-API-Key", "YOUR_API_KEY")
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();
client.close();POST /v1/colors in Java (java.net.http)
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://image-tools.p.apihiver.com/v1/colors"))
.header("Accept", "application/json")
.header("X-API-Key", "YOUR_API_KEY")
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());POST /v1/colors in Java (OkHttp)
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n");
Request request = new Request.Builder()
.url("https://image-tools.p.apihiver.com/v1/colors")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("X-API-Key", "YOUR_API_KEY")
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.build();
Response response = client.newCall(request).execute();POST /v1/colors in Java (Unirest)
HttpResponse<String> response = Unirest.post("https://image-tools.p.apihiver.com/v1/colors")
.header("Accept", "application/json")
.header("X-API-Key", "YOUR_API_KEY")
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n")
.asString();POST /v1/colors in C# (HttpClient)
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://image-tools.p.apihiver.com/v1/colors"),
Headers =
{
{ "Accept", "application/json" },
{ "X-API-Key", "YOUR_API_KEY" },
},
Content = new MultipartFormDataContent
{
new StringContent("")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("multipart/form-data"),
ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = "file.bin",
}
}
},
new StringContent("6")
{
Headers =
{
ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "count",
}
}
},
},
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}POST /v1/colors in C# (RestSharp)
var client = new RestClient("https://image-tools.p.apihiver.com/v1/colors");
var request = new RestRequest("", Method.Post);
request.AddHeader("Accept", "application/json");
request.AddHeader("X-API-Key", "YOUR_API_KEY");
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
var response = client.Execute(request);POST /v1/colors in Go (NewRequest)
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://image-tools.p.apihiver.com/v1/colors"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("X-API-Key", "YOUR_API_KEY")
req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}POST /v1/colors in Ruby (net::http)
require 'uri'
require 'net/http'
url = URI("https://image-tools.p.apihiver.com/v1/colors")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = 'application/json'
request["X-API-Key"] = 'YOUR_API_KEY'
request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n"
response = http.request(request)
puts response.read_bodyPOST /v1/colors in Swift (NSURLSession)
import Foundation
let headers = [
"Accept": "application/json",
"X-API-Key": "YOUR_API_KEY",
"content-type": "multipart/form-data; boundary=---011000010111000001101001"
]
let parameters = [
[
"name": "file",
"fileName": "file.bin",
"contentType": "multipart/form-data"
],
[
"name": "count",
"value": "6"
]
]
let boundary = "---011000010111000001101001"
var body = ""
var error: NSError? = nil
for param in parameters {
let paramName = param["name"]!
body += "--\(boundary)\r\n"
body += "Content-Disposition:form-data; name=\"\(paramName)\""
if let filename = param["fileName"] {
let contentType = param["content-type"]!
let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
if (error != nil) {
print(error as Any)
}
body += "; filename=\"\(filename)\"\r\n"
body += "Content-Type: \(contentType)\r\n\r\n"
body += fileContent
} else if let paramValue = param["value"] {
body += "\r\n\r\n\(paramValue)"
}
}
let request = NSMutableURLRequest(url: NSURL(string: "https://image-tools.p.apihiver.com/v1/colors")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error as Any)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()POST /v1/colors in Objective-C (NSURLSession)
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"Accept": @"application/json",
@"X-API-Key": @"YOUR_API_KEY",
@"content-type": @"multipart/form-data; boundary=---011000010111000001101001" };
NSArray *parameters = @[ @{ @"name": @"file", @"fileName": @"file.bin", @"contentType": @"multipart/form-data" },
@{ @"name": @"count", @"value": @"6" } ];
NSString *boundary = @"---011000010111000001101001";
NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
if (param[@"fileName"]) {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
[body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
if (error) {
NSLog(@"%@", error);
}
} else {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://image-tools.p.apihiver.com/v1/colors"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];POST /v1/colors in Kotlin (OkHttp)
val client = OkHttpClient()
val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001")
val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n")
val request = Request.Builder()
.url("https://image-tools.p.apihiver.com/v1/colors")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("X-API-Key", "YOUR_API_KEY")
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.build()
val response = client.newCall(request).execute()POST /v1/colors in C (libcurl)
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://image-tools.p.apihiver.com/v1/colors");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "X-API-Key: YOUR_API_KEY");
headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n");
CURLcode ret = curl_easy_perform(hnd);POST /v1/colors in Clojure (clj-http)
(require '[clj-http.client :as client])
(client/post "https://image-tools.p.apihiver.com/v1/colors" {:headers {:X-API-Key "YOUR_API_KEY"}
:multipart [{:name "file"
:content (clojure.java.io/file "file.bin")} {:name "count"
:content "6"}]
:accept :json})POST /v1/colors in OCaml (CoHTTP)
open Cohttp_lwt_unix
open Cohttp
open Lwt
let uri = Uri.of_string "https://image-tools.p.apihiver.com/v1/colors" in
let headers = Header.add_list (Header.init ()) [
("Accept", "application/json");
("X-API-Key", "YOUR_API_KEY");
("content-type", "multipart/form-data; boundary=---011000010111000001101001");
] in
let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n" in
Client.call ~headers ~body `POST uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)POST /v1/colors in R (httr)
library(httr)
url <- "https://image-tools.p.apihiver.com/v1/colors"
payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"count\"\r\n\r\n6\r\n-----011000010111000001101001--\r\n"
encode <- "multipart"
response <- VERB("POST", url, body = payload, add_headers('X-API-Key' = 'YOUR_API_KEY'), content_type("multipart/form-data"), accept("application/json"), encode = encode)
content(response, "text")POST /v1/colors in PowerShell (Invoke-WebRequest)
$headers=@{}
$headers.Add("Accept", "application/json")
$headers.Add("X-API-Key", "YOUR_API_KEY")
$headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
$response = Invoke-WebRequest -Uri 'https://image-tools.p.apihiver.com/v1/colors' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="count"
6
-----011000010111000001101001--
'POST /v1/colors in PowerShell (Invoke-RestMethod)
$headers=@{}
$headers.Add("Accept", "application/json")
$headers.Add("X-API-Key", "YOUR_API_KEY")
$headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
$response = Invoke-RestMethod -Uri 'https://image-tools.p.apihiver.com/v1/colors' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="count"
6
-----011000010111000001101001--
'POST /v1/colors in HTTP (HTTP/1.1)
POST /v1/colors HTTP/1.1
Accept: application/json
X-Api-Key: YOUR_API_KEY
Content-Type: multipart/form-data; boundary=---011000010111000001101001
Host: image-tools.p.apihiver.com
Content-Length: 251
-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="count"
6
-----011000010111000001101001--
Example response (200, application/json)
Success.
1{
2 "palette": [
3 {
4 "hex": "#ffffff",
5 "rgb": [
6 255,
7 255,
8 255
9 ],
10 "share": 0.8958
11 },
12 {
13 "hex": "#606060",
14 "rgb": [
15 96,
16 96,
17 96
18 ],
19 "share": 0.0272
20 },
21 {
22 "hex": "#c4c4c4",
23 "rgb": [
24 196,
25 196,
26 196
27 ],
28 "share": 0.0263
29 }
30 ],
31 "dominant": "#ffffff"
32}Errors
- 400 — A required parameter is missing or a value has the wrong format.
1{ 2 "error": { 3 "code": "INVALID_INPUT", 4 "message": "Provide a file upload, 'url', or 'base64'." 5 } 6}
Gateway errors (missing key, no subscription, rate limits) are listed in Error codes.