apyhub
Back
▣ FILE CONVERSION · FILE MANIPULATION

Compress Images API

Hosted on ApyHub

What it does

The image compression API reduces the file size of raster images. Send a public image URL or upload the file (up to 100 MB per request), set compression_percentage from 1 to 100, and get the compressed image back as a file download or as a time-limited signed URL. It supports JPEG, PNG, WebP, GIF, TIFF and BMP.

Set preserve_format to true to keep the original format, and use output to name the result. The four endpoints cover each combination of input and output: URL in or file in, file back or link back.

Use the image compression API wherever image weight costs you something. Compress user uploads before they reach storage, shrink product photos for faster catalog and landing pages, reduce attachment size in email and chat workflows, and cut bandwidth for mobile apps on slow connections. A batch job over an existing media library can lower storage and CDN costs without re-shooting a single image.

Compression works best as one step in an image pipeline. Resize to the display dimensions first with the Image Resize API, then compress. For modern web formats, convert with the JPEG to WebP API. When compressed scans or receipts need to become a document, the Image to PDF API turns them into a PDF.

▣ ENDPOINT 01 / 04
POST
Compress image (fetch by URL, download file)
https://api.eu.apyhub.com/apyhub/compress-images/url/download

QUICKSTART

GUIDE

Quickstart

Compress an image from a public URL by sending the image URL in the JSON body and the compression settings as query parameters.

curl -X POST "https://api.eu.apyhub.com/apyhub/compress-images/url/download?compression_percentage=75" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://assets.apyhub.com/samples/sample.jpg"}'

What you'll get back

Returns the compressed image as a binary file.

TRY ITLIVE · 30 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
Request body for URL-mode compression endpoints. Send as application/json. The url field is required and must be a publicly accessible image URL. All compression options (compression_percentage, preserve_format, output) are passed as query parameters — not in this body.
Publicly accessible URL of the raster image to compress. Supported formats — JPEG, PNG, WebP, GIF, TIFF, BMP. Hosts without a recognised scheme (http, https, ftp, sftp) receive an https:// prefix automatically.

About this endpoint

What it does

Compresses an image fetched from a public URL and returns the compressed file as binary data. You provide the source image URL in the request body and control compression with query parameters.

Query Parameter(s)

AttributeTypeMandatoryDescription
outputStringNoOutput file name.
preserve_formatBooleanNoDefaults to false.
compression_percentageIntegerYesCompression level as a percentage between 1 and 100.

Request Body

ParameterTypeMandatoryDescription
urlStringYesPublicly accessible URL of the raster image to compress. Supported formats: JPEG, PNG, WebP, GIF, TIFF, BMP. If the URL does not start with a recognised scheme (http, https, ftp, sftp), https:// is prefixed automatically.

Response

Returns binary file data for the compressed image.

ParameterTypeMandatoryDescription
binaryStringYesBinary content of the compressed image file.
▣ ENDPOINT 02 / 04
POST
Compress image (fetch by URL, return signed URL)
https://api.eu.apyhub.com/apyhub/compress-images/url/link

QUICKSTART

GUIDE

Quickstart

Compress an image from a public URL and get back a temporary download link.

curl -X POST "https://api.eu.apyhub.com/apyhub/compress-images/url/link?compression_percentage=75" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://assets.apyhub.com/samples/sample.jpg"}'

What you'll get back

Returns a JSON object with a data string field containing a time-limited pre-signed URL to the compressed image.

{
  "data": "https://storage.example.com/compress/my-compressed.png?X-Amz-Signature=def456&X-Amz-Expires=3600"
}
TRY ITLIVE · 30 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
Request body for URL-mode compression endpoints. Send as application/json. The url field is required and must be a publicly accessible image URL. All compression options (compression_percentage, preserve_format, output) are passed as query parameters — not in this body.
Publicly accessible URL of the raster image to compress. Supported formats — JPEG, PNG, WebP, GIF, TIFF, BMP. Hosts without a recognised scheme (http, https, ftp, sftp) receive an https:// prefix automatically.

About this endpoint

What it does

Compresses an image fetched from a publicly accessible URL and returns a time-limited signed URL for the compressed file.

Query Parameter(s)

AttributeTypeMandatoryDescription
outputStringNoOutput filename base.
preserve_formatBooleanNoDefault: false.
compression_percentageIntegerYesCompression level. Minimum: 1, maximum: 100.

Request Body

ParameterTypeMandatoryDescription
urlStringYesPublicly accessible URL of the raster image to compress. Supported formats: JPEG, PNG, WebP, GIF, TIFF, BMP. Must be a URI. Hosts without a recognised scheme (http, https, ftp, sftp) receive an https:// prefix automatically.

Response

Returns a JSON object with a data string field containing a time-limited pre-signed URL to the stored compressed image. The URL is always present on a 200 response and should be downloaded or forwarded before it expires.

AttributeTypeMandatoryDescription
dataStringYesTime-limited pre-signed URL to the stored compressed image. Always present on a 200 response. Download or forward the file before the URL expires.
▣ ENDPOINT 03 / 04
POST
Compress image (multipart upload, download file)
https://api.eu.apyhub.com/apyhub/compress-images/multi-part/download

QUICKSTART

GUIDE

Quickstart

Upload one image and get back the compressed file.

curl -X POST "https://api.eu.apyhub.com/apyhub/compress-images/multi-part/download?compression_percentage=75&output=my-compressed" \
  -H "apy-token: $APY_TOKEN" \
  -F "image=@/path/to/image.jpg"

What you'll get back

Returns a binary file (string with format: binary) containing the compressed image.

<compressed image bytes>
TRY ITLIVE · 30 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.
body*
Raster image file to compress. Supported formats — JPEG, PNG, WebP, GIF, TIFF, BMP.

About this endpoint

What it does

Compresses an uploaded raster image and returns the compressed file as a binary download. You send the image in a multipart request body, along with query parameters that control the output name, whether to preserve the original format, and the compression percentage.

Query Parameter(s)

AttributeTypeMandatoryDescription
outputStringNoOutput filename/base name for the compressed file.
preserve_formatBooleanNoDefault: false.
When true, preserves the original image format.
compression_percentageIntegerYesCompression percentage from 1 to 100.

Request Body

ParameterTypeMandatoryDescription
imageBinaryYesRaster image file to compress. Supported formats: JPEG, PNG, WebP, GIF, TIFF, BMP. Format: binary file upload.

Response

Returns a binary file download containing the compressed image. The response schema is a string with binary format, so the success response body is the file content itself rather than a JSON object.

Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.

▣ ENDPOINT 04 / 04
POST
Compress image (multipart upload, return signed URL)
https://api.eu.apyhub.com/apyhub/compress-images/multi-part/link

QUICKSTART

GUIDE

Quickstart

Compress a raster image from a public link by uploading the image file and setting the compression percentage.

curl -X POST "https://api.eu.apyhub.com/apyhub/compress-images/multi-part/link?compression_percentage=75" \
  -H "apy-token: $APY_TOKEN" \
  -F "image=@/path/to/image.jpg"

What you'll get back

Returns a JSON object with a data string field containing a time-limited pre-signed URL for the compressed image.

{
  "data": "https://storage.example.com/compress/my-compressed.jpg?X-Amz-Signature=abc123&X-Amz-Expires=3600"
}
TRY ITLIVE · 30 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.
body*
Raster image file to compress. Supported formats — JPEG, PNG, WebP, GIF, TIFF, BMP.

About this endpoint

What it does

Compresses a raster image uploaded as multipart form data and returns a time-limited signed URL for the compressed file. The compression level is controlled by compression_percentage, and you can optionally provide an output name and preserve the original image format.

Query Parameter(s)

AttributeTypeMandatoryDescription
outputStringNoOutput name for the compressed file.
preserve_formatBooleanNoDefault: false.
When true, preserves the original image format.
compression_percentageIntegerYesCompression level as an integer from 1 to 100.

Request Body

ParameterTypeMandatoryDescription
imageBinaryYesRaster image file to compress. Supported formats: JPEG, PNG, WebP, GIF, TIFF, BMP. Binary file upload.

Response

Returns a JSON object with a data string field containing a time-limited pre-signed URI to the compressed image. The URL is available on a 200 response and should be used before it expires.

ParameterTypeMandatoryDescription
dataStringYesTime-limited pre-signed URL to the stored compressed image. Always present on a 200 response. Download or forward the file before the URL expires.

Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.

▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.