画像を圧縮 API
このエンドポイントの機能: の PDF4me 画像を圧縮 REST API ファイルサイズを縮小 JPG、 PNGインテリジェントな圧縮アルゴリズムを使用したWebP画像。画像を Base64エンコードされた文字列出力フォーマットと圧縮レベルを設定し、圧縮された画像を受け取る。これらすべてを単一の同期処理で行う。 POST 呼び出し。これを使用して、eコマースページの製品画像を最適化したり、CMSパイプラインでアップロードされたアセットを縮小したり、サムネイルを生成したり、画像ファイルを扱うあらゆるアプリケーションで帯域幅コストを削減したりできます。
認証 API リクエスト
毎 PDF4me REST API 電話にはあなたの API キー Authorization ヘッダー。開発者ダッシュボードからキーを取得し、秘密に保管してください。クライアント側のコードにキーを公開しないでください。
見逃してはならない重要な事実
File Name, File Content, Image Type, and Compression Level must all be present in the request payload. A missing or empty field causes a 400 Bad Request error. Validate all four values in your code before sending the API call.
The API uses Image Type to select the correct decompression codec before re-encoding. Sending PNG data with Image Type set to JPG causes a format mismatch error. Always read the actual MIME type or file extension from your source and set Image Type to match.
Max reduces file size by 80-90%: ideal for thumbnails and social media previews where pixel-perfect detail is less important. Medium (60-70% reduction) suits most product and blog images. Low (30-40% reduction) is recommended when you need to preserve fine detail for print, zoom features, or professional photography archives.
REST API 終点
| 方法 | 終点 |
|---|---|
| POST | /api/v2/CompressImage |
ベースURL: https://api.pdf4me.com
パラメータ
⚠️ 4つのパラメータすべてが必要です。 の API いずれかのフィールドが欠落しているか空の場合はエラーを返します。
| パラメータ | 必須 | タイプ | その機能 | 例 |
|---|---|---|---|---|
| docName | Required | String | Filename of the source image including the file extension. Used to identify the format and name the output file. Use descriptive, extension-correct names. | product-hero.jpg |
| docContent | Required | Base64 | The complete image file encoded as a Base64 string. Supported formats: JPG/JPEG, PNG, WebP. Maximum file size: 50 MB. Do not include a data URL prefix: pass the raw Base64 string only. | JVBERi0xLjQK... |
| imageType | Required | Enum | Output image format. Must match the actual format of docContent. Accepted values: JPG · PNG · WebP | JPG |
| compressionLevel | Required | Enum | Compression intensity. Max: 80-90% size reduction, good quality (thumbnails, social media). Medium, 60-70% reduction, very good quality (product images, blogs). Low, 30-40% reduction, excellent quality (print, zoom, archives). | Medium |
出力フィールド
| パラメータ | 必須 | その機能 | 例 |
|---|---|---|---|
| jobIdExt | Optional | Your own reference for this call. It is stored with the API call log so you can correlate calls with your jobs. Type: string. | |
| integrations | Optional | Integration identifiers, forwarded unchanged with the job's notification settings. Type: array. | |
| isAsync | Optional | Set to `true` to process the action asynchronously and get a job to poll at `/api/v2/GetActionStatus`. Only honoured by actions that support asynchronous processing. Type: boolean. | |
| docName | Optional | Source file name including its extension. Several actions dispatch on the extension, so it should always be set; when omitted a per-action default is used. Type: string. | Filename of the compressed output image. |
| docContent | Required | The source file. Accepts the base64-encoded file content, a `pdf4meblobid://<id>` reference to a previously uploaded blob, or an `https` URL to the source document. Required: an empty value fails with `File is empty`. Type: string. | The compressed image file encoded as Base64. Decode to binary to save as a file. |
| docContentBytes | Optional | Alternative raw byte payload for the source file. Type: string. | |
| callBackUrl | Optional | Optional URL notified when an asynchronous job completes. Type: string. | |
| imageType | Optional | Matched case-insensitively; an unrecognised value falls back to the first entry. Type: string. | |
| compressionLevel | Optional | Matched case-insensitively; an unrecognised value falls back to the first entry. Type: string. | |
リクエスト例
ヘッダー
Content-Type: application/json
Authorization: YOUR_API_KEY
JSONペイロード
{
"docName": "product-hero.jpg",
"docContent": "JVBERi0xLjQK...",
"imageType": "JPG",
"compressionLevel": "Medium"
}
応答
{
"File Content": "BASE64_COMPRESSED_IMAGE_DATA",
"File Name": "product-hero.jpg"
}
コードサンプル
一般的な使用例
Compress JPG product photos to Medium level before serving on listing pages. Reduces page load time by 60-70% without visible quality loss on standard displays: directly improving Core Web Vitals and conversion rates.
Intercept image uploads in your CMS (WordPress, Contentful, Strapi) and run them through Compress Image at Max level before storing. Thumbnails and hero banners benefit most: users see no quality difference at normal viewing sizes.
High-resolution press images (300+ DPI, often 20-50 MB) can be compressed at Low level to maintain near-print quality while reducing file size by 30-40%. Ideal for photography portfolios, architectural galleries, and product zoom features.
よくある質問
▶ What is the maximum file size the Compress Image API accepts?
The API accepts images up to 50 MB. For best performance, keep images under 10 MB. Larger files increase processing time significantly and may exceed request timeouts on slow connections.
▶ Does Image Type need to match the actual binary format of File Content?
Yes: always. The API uses imageType to select the correct decompression codec before re-encoding at the chosen quality level. Sending PNG data with imageType set to JPG causes a format mismatch error. Read the actual MIME type or file extension from your source and set imageType to match exactly.
▶ Which Compression Level should I use for e-commerce product images?
Medium is the recommended level for most product images. It reduces file size by 60-70% while maintaining very good visual clarity for standard monitor and mobile display sizes. Use Low only when your product images include fine textures or details that customers zoom into.
▶ Can I convert and compress an image (e.g. PNG to WebP) in the same API call?
No: Compress Image only compresses within the same format. To convert between formats, call the Convert Image Format endpoint first, then pass the result to Compress Image in a second call. Chain these two calls in your application for a compress-and-convert pipeline.
▶ Is the output File Content returned as Base64 or binary?
The output File Content is Base64-encoded. Decode it to binary before writing to a file. In Python: base64.b64decode(response["File Content"]). In Node.js: Buffer.from(response["File Content"], "base64").