Skip to main content

Image Compression API: Step-by-Step Postman Test, Smaller JPGs, and SEO-Friendly Delivery

· 10 min read
SEO and Content Writer

Heavy images slow pages, inflate bandwidth bills, and work against Core Web Vitals—especially Largest Contentful Paint (LCP) when a large photo is the hero element. An image compression API lets you shrink JPG/PNG payloads in the pipeline (upload handlers, CMS imports, DAM workflows) instead of fixing files by hand.

This walkthrough uses PDF4me POST /api/v2/CompressImage with Postman: same pattern works in code once the request shape is clear. For a no-code first test, use the interactive Compress Image API Tester—it hits the same endpoint with form fields instead of raw JSON.

How to read this guide
  • Follow steps 1 → 5; screenshots match a real run (your timings and byte counts will vary with image content and network).
  • Replace the Postman placeholder {{BASE64_OF_INPUT_IMAGE}} with the Base64 of your file—no data:image/jpeg;base64, prefix in the JSON string.
  • After a successful call, decode the response to a .jpg and compare file size in Explorer (or macOS Finder) to the original.
The short version

1. Base64-encode your image → 2. POST https://api.pdf4me.com/api/v2/CompressImage with Content-Type: application/json and Authorization (your PDF4me API key) → 3. JSON body: docContent, docName, imageType, compressionLevel, async4. Expect 200 OK and a JPEG payload (raw bytes or Base64, depending on how your client displays it) → 5. Save and compare disk size to the source file.

Why teams use an image compression API (market context)

PriorityWhat changes with an API
Web performanceSmaller images decode faster and transfer quicker—important when LCP depends on a single large asset.
SEO & UXSearch engines reward pages that load reliably on mobile; lighter images reduce time-to-interactive friction.
OperationsOne HTTP contract for microservices, serverless upload handlers, and ETL jobs—no desktop tools in the loop.
CostLess egress and storage versus serving multi‑MB originals everywhere.

PDF4me exposes compression levels (Max, Medium, Low) so you can align with thumbnails vs. hero imagery. See the parameter overview in Compress Image (full API reference) and the quick table below.

Before you send the first request

Checklist
  1. API key: from the PDF4me dashboard (used in the Authorization header per official docs).
  2. Input format: JPG or PNG (see API Tester parameter notes).
  3. Large files / timeouts: set "async": true when recommended, or preprocess with Resize Image if pixels far exceed display size.
  4. Quota: failed auth or plan limits—use PDF4me troubleshooting if you see 401/402-style errors.

Reference: JSON body fields

FieldRole
docContentBase64 of the source image (required).
docNameOutput filename, e.g. output.jpg (required).
imageTypeOutput format, e.g. JPG or PNG.
compressionLevelMax, Medium, or Low.
asynctrue / false—use async when processing time might exceed client timeouts.

Step 1 — Start from a real “before” file

Use any large JPG for practice. The reference run below used a ~4.5 MB source file named input.jpg in Windows Explorer—large enough that compression is visibly meaningful in folder properties.

Windows Explorer showing a large JPG input file (~4.48 MB) before calling the compression API

Step 2 — Configure the Postman request (method + URL)

Open the Headers tab. At minimum you need Content-Type: application/json and your PDF4me key in Authorization (replace the placeholder from the screenshot with your real key).

Postman Headers tab for Compress Image: POST URL and Authorization

Step 3 — Set the raw JSON body

Choose Body → raw → JSON, then paste a payload shaped like this (swap in your Base64 string).

Postman Body tab with docContent, docName, imageType, compressionLevel, and async

{
"docContent": "PASTE_BASE64_HERE_NO_DATA_URL_PREFIX",
"docName": "output.jpg",
"imageType": "JPG",
"compressionLevel": "Max",
"async": false
}
Optional: minimal sanity checks before you click Send
  • JPEG Base64 often starts with /9j/ when the tool shows the string form—that maps to the JPEG file signature.
  • If Postman is slow, the request may still succeed—watch for 200 OK and save the output; consider async: true for production batch jobs.
  • For a guided form instead of JSON, open Compress Image in the API Tester and compare the same fields side by side.

Step 4 — Send and read the response

When the client shows Base64

If the Body viewer is set to Base64 and you see a long line starting with /9j/, the payload is JPEG data encoded for display. Decode it to a file and open it in an image viewer to confirm quality.

Postman 200 OK with response body interpreted as Base64 JPEG

When the client shows raw binary

Some views render raw bytes (metadata such as XMP may appear as readable text inside the stream). A 200 OK still means the compressed image was returned—save the body as output.jpg using your client’s “Save response” option.

Postman 200 OK with raw response body (binary / metadata visible)

Step 5 — Compare “after” file size on disk

After you write the response to disk, check Properties again. In the reference run, the compressed file landed near ~2.6 MB—a useful reduction on a multi‑megabyte photo while keeping workflow simple. Your ratio depends on content, dimensions, and compressionLevel; try Medium or Low if Max is too aggressive for product shots.

Windows Explorer showing compressed output.jpg file size after the API call

Troubleshooting (quick)

401 / auth errors

Confirm the key in Authorization and that the key is active. See API docs and troubleshooting.

Timeouts or very slow calls

Try "async": true where supported, or reduce pixel dimensions first with Resize Image.

“Corrupt” or empty output

Strip data:image/...;base64, prefixes from docContent, remove line breaks in the Base64 string, and verify the source file opens locally.

Automate without Postman

Summary: An image compression API belongs in the same toolbox as responsive images and CDN caching: it reduces bytes at the source so every downstream step is cheaper and faster. Start with the API Tester, reproduce the request in Postman using the steps above, then lift the JSON into your service or automation module when you are ready to ship.