Image Conversion API
Convert images between JPG, PNG, GIF, WEBP, BMP, AVIF, PDF, ICO, PSD, TIFF, EPS, and HEIC (source only) with one POST request — the exact engine behind TransConvert's website converter.
cURL
curl -X POST \ .../api/v1/convert.php \ -H "Authorization: Bearer ..." \ -F "category=image" \ -F "target=PNG" \ -F "file=@photo.jpg" \ -o output.png
POST
https://transconvert.com/api/v1/convert.php
パラメーター
| Field | Description |
|---|---|
Authorization | Required. "Bearer tc_live_...". |
category | Set to "image". |
target | Required. Output format code, e.g. "PNG", "PDF", "ICO". |
file | Required. The image (or PDF, when converting a PDF page to an image). |
pdf_mode | "pages" (default) or "extract" — only relevant when the source is a PDF. |
pdf_pages | "all" (default) or "first" — only relevant when the source is a PDF. |
pdf_quality | "normal" (default, 150 DPI) or "high" (300 DPI) — only relevant when the source is a PDF. |
サンプルコード
TransConvert
curl -X POST \ https://transconvert.com/api/v1/convert.php \ -H "Authorization: Bearer tc_live_your_key_here" \ -F "category=image" \ -F "target=PNG" \ -F "file=@photo.jpg" \ -o output.png
<?php $ch = curl_init('https://transconvert.com/api/v1/convert.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer tc_live_your_key_here'], CURLOPT_POSTFIELDS => [ 'category' => 'image', 'target' => 'PNG', 'file' => new CURLFile('photo.jpg'), ], ]); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status === 200) { file_put_contents('output.png', $response); } else { $error = json_decode($response, true); echo $error['error']['message']; }
const form = new FormData(); form.append('category', 'image'); form.append('target', 'PNG'); form.append('file', new Blob([fs.readFileSync('photo.jpg')]), 'photo.jpg'); const res = await fetch('https://transconvert.com/api/v1/convert.php', { method: 'POST', headers: { Authorization: 'Bearer tc_live_your_key_here' }, body: form, }); if (res.ok) { fs.writeFileSync('output.png', Buffer.from(await res.arrayBuffer())); } else { const { error } = await res.json(); console.error(error.message); }
import requests with open('photo.jpg', 'rb') as f: response = requests.post( 'https://transconvert.com/api/v1/convert.php', headers={'Authorization': 'Bearer tc_live_your_key_here'}, data={'category': 'image', 'target': 'PNG'}, files={'file': f}, ) if response.status_code == 200: with open('output.png', 'wb') as out: out.write(response.content) else: print(response.json()['error']['message'])
# gem install multipart-post require 'net/http' require 'net/http/post/multipart' url = URI('https://transconvert.com/api/v1/convert.php') File.open('photo.jpg') do |file| req = Net::HTTP::Post::Multipart.new url, 'category' => 'image', 'target' => 'PNG', 'file' => UploadIO.new(file, 'application/octet-stream', 'photo.jpg') req['Authorization'] = 'Bearer tc_live_your_key_here' res = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http| http.request(req) end if res.code == '200' File.write('output.png', res.body) else puts JSON.parse(res.body)['error']['message'] end end
// Gradle: implementation("com.squareup.okhttp3:okhttp:4.+") OkHttpClient client = new OkHttpClient(); RequestBody body = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("category", "image") .addFormDataPart("target", "PNG") .addFormDataPart("file", "photo.jpg", RequestBody.create(new File("photo.jpg"), MediaType.parse("application/octet-stream"))) .build(); Request request = new Request.Builder() .url("https://transconvert.com/api/v1/convert.php") .header("Authorization", "Bearer tc_live_your_key_here") .post(body) .build(); try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { Files.write(Paths.get("output.png"), response.body().bytes()); } else { System.err.println(response.body().string()); } }
レスポンス
成功時(200):変換後のファイルの生バイト列を、対応するContent-TypeおよびContent-Dispositionヘッダーとともに返します。失敗時:{"error": {"code": "...", "message": "..."}} という形のJSONボディを、対応するHTTPステータスコードとともに返します。詳細は下記の「エラー」を参照してください。
| Header | Value |
|---|---|
Content-Type | 変換後のファイルの実際のMIMEタイプです(例:image/png、application/pdf)。 |
Content-Disposition | 通常のファイルダウンロードと同様、attachment; filename="..." という形で推奨ファイル名が示されます。 |
Content-Length | レスポンスボディのサイズ(バイト単位)です。 |
エラーはすべて同じJSON形式です。例えば割り当て超過の場合:
429 Too Many Requests
{
"error": {
"code": "quota_exceeded",
"message": "Monthly API allowance of 5000 conversion-minutes reached.",
"limit": 5000,
"used": 5000
}
}
エラー
失敗時は必ず、プログラムで分岐に使える "code" と、人が読める "message" を含むJSONエラーが返されます。エラーによっては追加のフィールドを含むこともあります(例えば quota_exceeded には "limit" と "used" が含まれます)。
| Status & code | When it happens |
|---|---|
401 missing_key | Authorizationヘッダーが送信されませんでした。 |
401 invalid_key | キーが存在しないか、失効しています。 |
403 account_suspended | このキーを所有するアカウントは停止されています。 |
403 plan_required | アカウントがFreeプランです — API利用にはBasic、Lite、Pro、Teamのいずれかのプランが必要です。 |
400 invalid_category | "category" が "image" または "document" ではありませんでした。 |
400 missing_target | "target" が空でした。 |
400 no_file | ファイルが送信されなかったか、アップロードに失敗しました — フィールド名は "file" にする必要があります。 |
413 file_too_large | ファイルがプランの最大アップロードサイズを超えています。 |
429 quota_exceeded | プランの月間変換分の割り当てを使い切りました。翌月の初めにリセットされます。 |
429 concurrency_limit | このアカウントで同時に実行中の変換が多すぎます(ウェブサイトと共有されています) — いずれかが完了するのを待ってから再試行してください。 |
422 conversion_failed | ファイル自体を変換できませんでした — 理由は "message" に記載されています。ステータスコードは理由によって異なります: 400/415/422 は、何度再試行してもそのファイルやtargetでは成功しないことを意味します。500/503 はサーバー側の問題であり、特に503は短い間隔での再試行を試す価値があります。 |
Supported formats
変換元として使用可能:
JPG, PNG, GIF, WEBP, BMP, AVIF, PDF, PSD, TIFF, EPS, HEIC
変換先として使用可能:
JPG, PNG, GIF, WEBP, BMP, AVIF, PDF, ICO, PSD, TIFF, EPS