<?php
// APIエンドポイントとAPIキー
$endpoint = 'https://events-front.mixeder.net/v2/convertion/heictopng/';
$apiKey = 'YOUR_API_KEY';
// 送信するファイルパス
$filePath = '/path/to/your/image.heic';
// cURLを使用してAPIにPOSTリクエストを送信
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $endpoint,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"api-key: $apiKey",
"Content-Type: multipart/form-data"
],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile($filePath)
]
]);
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo 'cURL Error: ' . curl_error($curl);
exit;
}
curl_close($curl);
// レスポンスを表示
$data = json_decode($response, true);
if (isset($data['success']) && $data['success'] === true) {
// PNG画像の保存
file_put_contents('/path/to/output/image.png', base64_decode($data['converted_image']));
echo "Image converted successfully.";
} else {
echo "Error: " . ($data['error'] ?? 'Unknown error');
}