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 -X POST \ .../api/v1/convert.php \ -H "Authorization: Bearer ..." \ -F "category=image" \ -F "target=PNG" \ -F "file=@photo.jpg" \ -o output.png
https://transconvert.com/api/v1/convert.php
Parametreler
| 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. |
Örnekler
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()); } }
Yanıt
Başarılı olduğunda (200): dönüştürülmüş dosyanın ham baytları, buna uygun Content-Type ve Content-Disposition başlıklarıyla birlikte döner. Başarısız olduğunda: {"error": {"code": "...", "message": "..."}} şeklinde bir JSON gövdesi, eşleşen bir HTTP durum koduyla birlikte döner — aşağıdaki Hatalar bölümüne bakın.
| Header | Value |
|---|---|
Content-Type | Dönüştürülmüş dosyanın gerçek MIME türü (ör. image/png, application/pdf). |
Content-Disposition | attachment; filename="..." — herhangi bir dosya indirmesinde olduğu gibi önerilen bir dosya adı. |
Content-Length | Yanıt gövdesinin bayt cinsinden boyutu. |
Her hata aynı JSON yapısını izler, örneğin kota aşıldığında:
{
"error": {
"code": "quota_exceeded",
"message": "Monthly API allowance of 5000 conversion-minutes reached.",
"limit": 5000,
"used": 5000
}
}
Hatalar
Her başarısızlık, kodunuzun dallanabileceği bir "code" ile birlikte insan tarafından okunabilir bir "message" içeren bir JSON hata zarfı döndürür. Bazı hatalar ek alanlar içerir (örneğin quota_exceeded, "limit" ve "used" içerir).
| Status & code | When it happens |
|---|---|
401 missing_key | Authorization başlığı gönderilmedi. |
401 invalid_key | Anahtar mevcut değil veya iptal edilmiş. |
403 account_suspended | Bu anahtara sahip hesap askıya alınmış. |
403 plan_required | Hesap Free planında — API erişimi Basic, Lite, Pro veya Team gerektirir. |
400 invalid_category | "category", "image" veya "document" değildi. |
400 missing_target | "target" boştu. |
400 no_file | Dosya gönderilmedi veya yükleme başarısız oldu — alanın adı "file" olmalı. |
413 file_too_large | Dosya, planınızın izin verdiği en büyük yükleme boyutunu aşıyor. |
429 quota_exceeded | Planın aylık dönüştürme dakikası kotası tükendi. Bir sonraki takvim ayının başında sıfırlanır. |
429 concurrency_limit | Bu hesap için aynı anda çalışan çok fazla dönüştürme var (web sitesiyle paylaşılır) — birinin bitmesini bekleyip tekrar deneyin. |
422 conversion_failed | Dosyanın kendisi dönüştürülemedi — "message" nedenini açıklar. Durum kodu nedene göre değişir: 400/415/422, dosyanın veya hedefin kaç kez denerseniz deneyin çalışmayacağı anlamına gelir; 500/503 sunucu tarafında bir sorun olduğunu gösterir, özellikle 503 için kısa bir yeniden deneme mantıklıdır. |
Supported formats
Kaynak olarak kabul edilir:
JPG, PNG, GIF, WEBP, BMP, AVIF, PDF, PSD, TIFF, EPS, HEIC
Hedef olarak kullanılabilir:
JPG, PNG, GIF, WEBP, BMP, AVIF, PDF, ICO, PSD, TIFF, EPS