Compress an image
curl --request POST \
--url https://integration.smartpng.com/api/compress \
--header 'Content-Type: multipart/form-data' \
--form api_key=sp_live_abc123def456ghi789 \
--form 'file=@example-file;type=image/png'import requests
url = "https://integration.smartpng.com/api/compress"
files = { "file": ("example-file", open("example-file", "rb"), "image/png") }
payload = { "api_key": "sp_live_abc123def456ghi789" }
response = requests.post(url, data=payload, files=files)
print(response.text)const form = new FormData();
form.append('api_key', 'sp_live_abc123def456ghi789');
form.append('file', '<string>');
const options = {method: 'POST'};
options.body = form;
fetch('https://integration.smartpng.com/api/compress', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://integration.smartpng.com/api/compress",
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=\"api_key\"\r\n\r\nsp_live_abc123def456ghi789\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: image/png\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://integration.smartpng.com/api/compress")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\nsp_live_abc123def456ghi789\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: image/png\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();using RestSharp;
var options = new RestClientOptions("https://integration.smartpng.com/api/compress");
var client = new RestClient(options);
var request = new RestRequest("");
request.AlwaysMultipartFormData = true;
request.FormBoundary = "---011000010111000001101001";
request.AddParameter("api_key", "sp_live_abc123def456ghi789");
request.AddFile("file", "example-file");
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
{
"success": true,
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "completed",
"message": "Image compressed successfully",
"compressed_data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"original_size": 125678,
"compressed_size": 78456,
"compression_ratio": 37.56,
"credits_remaining": 499
}
Endpoints
POST /compress
Upload an image, compress it immediately, and return the optimized file as base64.
POST
https://integration.smartpng.com/api
/
compress
Compress an image
curl --request POST \
--url https://integration.smartpng.com/api/compress \
--header 'Content-Type: multipart/form-data' \
--form api_key=sp_live_abc123def456ghi789 \
--form 'file=@example-file;type=image/png'import requests
url = "https://integration.smartpng.com/api/compress"
files = { "file": ("example-file", open("example-file", "rb"), "image/png") }
payload = { "api_key": "sp_live_abc123def456ghi789" }
response = requests.post(url, data=payload, files=files)
print(response.text)const form = new FormData();
form.append('api_key', 'sp_live_abc123def456ghi789');
form.append('file', '<string>');
const options = {method: 'POST'};
options.body = form;
fetch('https://integration.smartpng.com/api/compress', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://integration.smartpng.com/api/compress",
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=\"api_key\"\r\n\r\nsp_live_abc123def456ghi789\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: image/png\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://integration.smartpng.com/api/compress")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\nsp_live_abc123def456ghi789\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: image/png\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();using RestSharp;
var options = new RestClientOptions("https://integration.smartpng.com/api/compress");
var client = new RestClient(options);
var request = new RestRequest("");
request.AlwaysMultipartFormData = true;
request.FormBoundary = "---011000010111000001101001";
request.AddParameter("api_key", "sp_live_abc123def456ghi789");
request.AddFile("file", "example-file");
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
{
"success": true,
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "completed",
"message": "Image compressed successfully",
"compressed_data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"original_size": 125678,
"compressed_size": 78456,
"compression_ratio": 37.56,
"credits_remaining": 499
}
Overview
Use this endpoint when you want SmartPNG to compress a single image synchronously and return the optimized file in the same response.Notes
- The request must be
multipart/form-data. api_keyandfileare required.- One successful compression consumes one credit.
- The response includes
compressed_dataas base64 and the updatedcredits_remainingvalue.
Body
multipart/form-data
Response
Compression successful
Example:
true
Example:
"a1b2c3d4-e5f6-7890-abcd-ef1234567890"
Available options:
completed Example:
"completed"
Example:
"Image compressed successfully"
Base64-encoded compressed image
Example:
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
Example:
125678
Example:
78456
Example:
37.56
Example:
499
