Compress Image API

Intelligently Reduce JPG & PNG File Sizes Programmatically.

hero banner

Code Examples in Popular Languages

Integrate our Compress Image API easily into your apps with comprehensive code examples in popular languages to get started quickly.

CURL Request
curl --location 'https://theonlineconverter.com/api/v1/image-compressor' \
--header 'Content-Type: application/json' \
--header 'x-api-key: enter_your_api_key' \
--form 'file=@"/D:/data/Images/png/30mb.png"' \
--form 'quality="40"'
JavaScript Fetch
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "enter_your_api_key");

const formdata = new FormData();
formdata.append("file", fileInput.files[0], "/D:/data/Images/png/30mb.png");
formdata.append("quality", "40");

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: formdata,
  redirect: "follow"
};

fetch("https://theonlineconverter.com/api/v1/image-compressor", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
Ruby Net::HTTP
import requests
import json

url = "https://theonlineconverter.com/api/v1/image-compressor"

payload = {'quality': '40'}
files=[
  ('file',('30mb.png',open('/D:/data/Images/png/30mb.png','rb'),'image/png'))
]
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'enter_your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
Python Requests
import requests
import json

url = "https://theonlineconverter.com/api/v1/image-compressor"

payload = {'quality': '40'}
files=[
  ('file',('30mb.png',open('/D:/data/Images/png/30mb.png','rb'),'image/png'))
]
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'enter_your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
PHP Guzzle
<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json',
  'x-api-key' => 'enter_your_api_key'
];
$options = [
  'multipart' => [
    [
      'name' => 'file',
      'contents' => Utils::tryFopen('/D:/data/Images/png/30mb.png', 'r'),
      'filename' => '/D:/data/Images/png/30mb.png',
      'headers'  => [
        'Content-Type' => '<Content-type header>'
      ]
    ],
    [
      'name' => 'quality',
      'contents' => '40'
    ]
]];
$request = new Request('POST', 'https://theonlineconverter.com/api/v1/image-compressor', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
Java HttpURLConnection
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("file","/D:/data/Images/png/30mb.png",
    RequestBody.create(MediaType.parse("application/octet-stream"),
    new File("/D:/data/Images/png/30mb.png")))
  .addFormDataPart("quality","40")
  .build();
Request request = new Request.Builder()
  .url("https://theonlineconverter.com/api/v1/image-compressor")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("x-api-key", "enter_your_api_key")
  .build();
Response response = client.newCall(request).execute();
Go net/http
package main

import (
  "fmt"
  "bytes"
  "mime/multipart"
  "os"
  "path/filepath"
  "net/http"
  "io"
)

func main() {

  url := "https://theonlineconverter.com/api/v1/image-compressor"
  method := "POST"

  payload := &bytes.Buffer{}
  writer := multipart.NewWriter(payload)
  file, errFile1 := os.Open("/D:/data/Images/png/30mb.png")
  defer file.Close()
  part1,
         errFile1 := writer.CreateFormFile("file",filepath.Base("/D:/data/Images/png/30mb.png"))
  _, errFile1 = io.Copy(part1, file)
  if errFile1 != nil {
    fmt.Println(errFile1)
    return
  }
  _ = writer.WriteField("quality", "40")
  err := writer.Close()
  if err != nil {
    fmt.Println(err)
    return
  }


  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("x-api-key", "enter_your_api_key")

  req.Header.Set("Content-Type", writer.FormDataContentType())
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := io.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
C# HttpClient
var options = new RestClientOptions("https://theonlineconverter.com")
{
  MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("/api/v1/image-compressor", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-api-key", "enter_your_api_key");
request.AlwaysMultipartFormData = true;
request.AddFile("file", "/D:/data/Images/png/30mb.png");
request.AddParameter("quality", "40");
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);

Key Features & Capabilities

Our API uses a suite of best-in-class optimization techniques to achieve maximum compression for your images.

Simple User Interface

Intelligent Compression

Utilizes both lossy (for JPG/WEBP) and lossless (for PNG) compression techniques to achieve the best possible size reduction for each image type.

Simple Data Format

Adjustable Quality Control

Fine-tune the compression level for JPEG and WEBP images with a simple quality parameter (1-100) to find the perfect balance between file size and visual quality.

Time

Multi-Format Support

Optimize a wide range of popular image formats, including JPEG, PNG, WEBP, and GIF, through a single, unified API endpoint.

Secure Data

PNG Optimization

For PNGs, we use advanced techniques like color quantization and stripping of unnecessary chunks to reduce file size while preserving full alpha transparency.

Universal Access

Metadata Stripping

Automatically remove non-essential metadata (like EXIF data from cameras) to further reduce file size and enhance user privacy.

Freedom

Secure & Confidential

All images are processed over encrypted connections. We guarantee confidentiality with a strict data privacy policy and do not store your files.

Frequently Asked Questions

Find answers to common questions about our Compress Image API to understand how it optimizes your visual content.

Lossless compression (used for PNGs) reduces file size without discarding any image data, so quality is perfectly preserved. Lossy compression (used for JPEGs) removes some non-essential data, resulting in much smaller files but a slight, often imperceptible, reduction in quality.

The compression ratio depends heavily on the original image. Unoptimized, high-resolution JPEGs can often be reduced by 70% or more. PNGs with simple color palettes also compress very well. The results will vary for each image.

A quality setting between 75 and 85 is usually the sweet spot, offering a great reduction in file size with very little noticeable difference in quality. For web thumbnails, you can often go even lower. We recommend experimenting to find what works best for you.

No. This API only reduces the file size (in kilobytes/megabytes). The pixel dimensions (width and height) of the image remain exactly the same. For changing dimensions, you would use an Image Resizing API.

EXIF data is metadata embedded in image files by digital cameras. It can include information like the camera model, shutter speed, and GPS location. Removing it makes the file smaller and is a good practice for privacy.

Yes, the API can optimize animated GIFs by reducing the color palette and removing redundant frames, which can significantly lower their file size.

Absolutely. We use end-to-end TLS encryption for all data transfers. Your images are processed securely and are permanently deleted from our servers immediately after the job is complete.