Skip to main content
POST
/
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'
{
  "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_key and file are required.
  • One successful compression consumes one credit.
  • The response includes compressed_data as base64 and the updated credits_remaining value.

Body

multipart/form-data
api_key
string
required

SmartPNG API key

Example:

"sp_live_abc123def456ghi789"

file
file
required

Image file to compress

Response

Compression successful

success
boolean
required
Example:

true

job_id
string<uuid>
required
Example:

"a1b2c3d4-e5f6-7890-abcd-ef1234567890"

status
enum<string>
required
Available options:
completed
Example:

"completed"

message
string
required
Example:

"Image compressed successfully"

compressed_data
string<byte>
required

Base64-encoded compressed image

Example:

"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="

original_size
integer
required
Example:

125678

compressed_size
integer
required
Example:

78456

compression_ratio
number<float>
required
Example:

37.56

credits_remaining
integer
required
Example:

499