# Image tools API

> Resize and convert pictures, remove backgrounds, and compare pictures by how they look.

Upload a picture and get it back resized or in another format (WebP, AVIF, JPEG, PNG), with its background removed, or as a fingerprint for finding duplicates. HEIC photos from iPhones are read too. Metadata such as the GPS position is always removed. Pictures are processed and deleted; nothing is kept or logged.

Base URL `https://api.dharun.dev`. No API key. Answers are JSON, `{ "data": ..., "meta": { ... } }`, and errors are `{ "error": { "code", "message" } }` with a matching HTTP status. Rate limit: 600 requests a minute per client.

## Resize and convert a picture

`POST /v1/image/convert`

Returns the picture itself, turned upright from its EXIF orientation, without metadata. fit=inside keeps the whole picture within width and height and never enlarges it; cover fills the box and crops the middle; fill stretches. Options go in the query string, or as form fields when the file is sent as multipart/form-data.

Send: A picture: JPEG, PNG, WebP, HEIC, AVIF, GIF, BMP or TIFF, up to 10 MB. Post the file as the request body, or as `multipart/form-data`. Sample file: https://api.dharun.dev/samples/photo.jpg

What you send is never written to the log, and the answer is not cached.

Parameters:

- `format` (query): Output format. Default webp. One of: jpeg, png, webp, avif, gif, tiff.
- `width` (query): Width in pixels, 1 to 8000.
- `height` (query): Height in pixels, 1 to 8000.
- `fit` (query): How the picture fits width and height. Default inside. One of: inside, cover, fill.
- `quality` (query): JPEG, WebP and AVIF quality, 1 to 100. Default 80.

Example: `POST` https://api.dharun.dev/v1/image/convert?format=webp&width=400 (returns the image itself)

## Size, format and metadata of a picture

`POST /v1/image/info`

Format, size, colour space, pages, orientation, the camera, and whether the picture carries EXIF data or a GPS position.

Send: A picture: JPEG, PNG, WebP, HEIC, AVIF, GIF, BMP or TIFF, up to 10 MB. Post the file as the request body, or as `multipart/form-data`. Sample file: https://api.dharun.dev/samples/photo.jpg

What you send is never written to the log, and the answer is not cached.

Example: `POST` https://api.dharun.dev/v1/image/info

Response:

```json
{
  "data": {
    "format": "jpeg",
    "width": 853,
    "height": 640,
    "bands": 3,
    "alpha": false,
    "colour_space": "srgb",
    "pages": 1,
    "orientation": 1,
    "has_exif": false,
    "has_location": false,
    "bytes": 16053
  },
  "meta": {}
}
```

## Remove the background

`POST /v1/image/remove-background`

Returns the picture as a PNG with the background transparent, cut out by the IS-Net model. Works best on one clear subject: a product, a person, an animal. Takes a few seconds; pictures larger than 4096 pixels are made smaller. Options go in the query string, or as form fields when the file is sent as multipart/form-data.

Send: A picture: JPEG, PNG, WebP, HEIC, AVIF, GIF, BMP or TIFF, up to 10 MB. Post the file as the request body, or as `multipart/form-data`. Sample file: https://api.dharun.dev/samples/photo.jpg

What you send is never written to the log, and the answer is not cached.

Parameters:

- `format` (query): png (default), webp, or mask: the cut-out mask alone, white where the subject is. One of: png, webp, mask.

Example: `POST` https://api.dharun.dev/v1/image/remove-background (returns the image itself)

## Perceptual hash of a picture

`POST /v1/image/hash`

Three 64-bit fingerprints (average, difference and DCT-based perceptual hashes) that stay nearly the same when a picture is resized, recompressed or slightly edited. Pictures whose perceptual hashes differ by 10 bits or fewer look alike.

Send: A picture: JPEG, PNG, WebP, HEIC, AVIF, GIF, BMP or TIFF, up to 10 MB. Post the file as the request body, or as `multipart/form-data`. Sample file: https://api.dharun.dev/samples/photo.jpg

What you send is never written to the log, and the answer is not cached.

Example: `POST` https://api.dharun.dev/v1/image/hash

Response:

```json
{
  "data": {
    "average": "fff3e7c3c3c3c300",
    "difference": "16660c9696868e30",
    "perceptual": "e4cc9b3199939393",
    "width": 853,
    "height": 640
  },
  "meta": {
    "note": "Hex 64-bit hashes. Compare two pictures by counting the bits that differ: up to about 10 of 64 means they look alike."
  }
}
```

## Compare two pictures

`POST /v1/image/compare`

Send two pictures as form fields. Returns the bits by which each hash differs, a score from 0 to 1, and whether they look like the same picture.

Send: Two pictures, as multipart/form-data, up to 10 MB each. Post the file as the request body, or as `multipart/form-data` with one field per file. Sample file: https://api.dharun.dev/samples/photo.jpg

What you send is never written to the log, and the answer is not cached.

Example: `POST` https://api.dharun.dev/v1/image/compare

Response:

```json
{
  "data": {
    "similar": true,
    "distance": {
      "average": 0,
      "difference": 0,
      "perceptual": 0
    },
    "score": 1,
    "pictures": [
      {
        "average": "fff3e7c3c3c3c300",
        "difference": "16660c9696868e30",
        "perceptual": "e4cc9b3199939393",
        "width": 853,
        "height": 640
      },
      {
        "average": "fff3e7c3c3c3c300",
        "difference": "16660c9696868e30",
        "perceptual": "e4cc9b3199939393",
        "width": 853,
        "height": 640
      }
    ]
  },
  "meta": {
    "note": "Distances are bits that differ, of 64. similar is true when the perceptual hashes differ by 10 bits or fewer. score is 1 for the same picture."
  }
}
```

## Data source

- [IS-Net (DIS), general-use weights](https://github.com/xuebinqin/DIS), isnet-general-use@rembg-v0.0.0, retrieved 2026-10-14T20:48:57Z. Licence: Apache-2.0. Background removal with IS-Net (Qin et al., Highly Accurate Dichotomous Image Segmentation, ECCV 2022), Apache-2.0.
