# PNG Via HEIC API

HEICtoPNG APIは、HEIC形式の画像をPNG形式に変換するためのAPIです。iOSやmacOSデバイスで利用されるHEIC形式の画像を、より一般的なPNG形式に変換することで、ウェブやアプリケーションでの互換性を向上させます。

***

#### **概要**

このAPIは、高品質な画像変換を迅速かつ確実に行うために設計されています。以下の特徴を備えています：

* **互換性向上**: HEIC形式をサポートしないプラットフォームやブラウザでも利用可能に。
* **迅速な変換**: サーバー側で高速に画像変換を処理。
* **自動化対応**: システムやワークフローに組み込んで効率化。

***

#### **料金体系**

* **1000アクセスごとに100円**\
  大量の画像変換が必要なプロジェクトでもコストを抑えて利用可能です。

***

#### **エンドポイント**

```
https://events-front.mixeder.net/v2/convertion/heictopng/
```

***

#### **利用方法**

**HTTPメソッド**

* `POST`

**リクエストヘッダー**

| ヘッダー名     | 説明         | 必須 |
| --------- | ---------- | -- |
| `api-key` | ユーザーのAPIキー | はい |

**リクエストボディ**

| パラメーター名 | タイプ    | 説明            | 必須 |
| ------- | ------ | ------------- | -- |
| `file`  | `file` | HEIC形式の画像ファイル | はい |

**レスポンス例**

**成功時**

```json
{
  "success": true,
  "converted_image": "data:image/png;base64,iVBORw0..."
}
```

| フィールド名            | タイプ       | 説明                  |
| ----------------- | --------- | ------------------- |
| `success`         | `boolean` | 成功ステータス             |
| `converted_image` | `string`  | Base64エンコードされたPNG画像 |

**失敗時**

```json
{
  "error": "Conversion failed"
}
```

| フィールド名  | タイプ      | 説明       |
| ------- | -------- | -------- |
| `error` | `string` | エラーメッセージ |

***

#### **利用の流れ**

1. **APIキーの準備**\
   サービスから発行されたAPIキーを取得し、リクエストヘッダーに設定します。
2. **HEIC画像のアップロード**\
   リクエストボディにHEIC形式の画像ファイルを添付して、エンドポイントにリクエストを送信します。
3. **PNG画像の取得**\
   レスポンスとして返されるBase64エンコードされたPNG画像を取得し、保存または表示に利用します。
4. **利用状況の確認**\
   利用状況はAPIの請求システムで自動的に処理されます。

***

#### **活用事例**

* **写真管理システム**\
  HEIC形式で撮影された写真を自動的にPNGに変換し、Webアプリで表示可能に。
* **クラウドストレージ**\
  HEIC画像をアップロード時に変換して互換性を確保。
* **マルチデバイス対応**\
  モバイル端末で撮影されたHEIC画像を変換し、デスクトップ環境での利用を可能に。

***

#### **注意事項**

1. **APIキーの保護**\
   APIキーは他人と共有しないでください。
2. **ファイルサイズの制限**\
   HEIC画像のサイズが制限を超えないよう注意してください。

***

このAPIを利用することで、効率的な画像変換プロセスを構築し、異なるフォーマット間の互換性を向上させることが可能です。

## サンプルコード

***

#### **1. PHP**

```php
<?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');
}
```

***

#### **2. Python**

```python
import requests

# APIエンドポイントとAPIキー
url = "https://events-front.mixeder.net/v2/convertion/heictopng/"
api_key = "YOUR_API_KEY"
file_path = "path/to/your/image.heic"

# ファイルをPOSTリクエストで送信
with open(file_path, "rb") as file:
    headers = {"api-key": api_key}
    files = {"file": file}
    response = requests.post(url, headers=headers, files=files)

# レスポンスを解析
if response.status_code == 200:
    data = response.json()
    if data.get("success"):
        # PNG画像の保存
        with open("output_image.png", "wb") as output:
            output.write(base64.b64decode(data["converted_image"]))
        print("Image converted successfully.")
    else:
        print(f"Error: {data.get('error')}")
else:
    print(f"HTTP Error: {response.status_code}")
```

***

#### **3. Node.js**

```javascript
const axios = require("axios");
const fs = require("fs");
const FormData = require("form-data");

// APIエンドポイントとAPIキー
const url = "https://events-front.mixeder.net/v2/convertion/heictopng/";
const apiKey = "YOUR_API_KEY";

// ファイルを送信
const filePath = "./path/to/your/image.heic";
const formData = new FormData();
formData.append("file", fs.createReadStream(filePath));

axios.post(url, formData, {
    headers: {
        "api-key": apiKey,
        ...formData.getHeaders()
    }
}).then(response => {
    if (response.data.success) {
        // PNG画像を保存
        const buffer = Buffer.from(response.data.converted_image, "base64");
        fs.writeFileSync("./output_image.png", buffer);
        console.log("Image converted successfully.");
    } else {
        console.error("Error:", response.data.error);
    }
}).catch(error => {
    console.error("Error:", error.message);
});
```

***

#### **4. Ruby**

```ruby
require "net/http"
require "uri"
require "json"
require "base64"

# APIエンドポイントとAPIキー
url = URI.parse("https://events-front.mixeder.net/v2/convertion/heictopng/")
api_key = "YOUR_API_KEY"

# ファイルを読み込む
file_path = "path/to/your/image.heic"
file = File.open(file_path, "rb")

# リクエストを送信
request = Net::HTTP::Post.new(url)
request["api-key"] = api_key
form_data = [["file", file]]
request.set_form(form_data, "multipart/form-data")

response = Net::HTTP.start(url.hostname, url.port, use_ssl: true) do |http|
  http.request(request)
end

# レスポンスを解析
if response.code.to_i == 200
  data = JSON.parse(response.body)
  if data["success"]
    File.open("output_image.png", "wb") do |f|
      f.write(Base64.decode64(data["converted_image"]))
    end
    puts "Image converted successfully."
  else
    puts "Error: #{data['error']}"
  end
else
  puts "HTTP Error: #{response.code}"
end
```

***

#### **5. cURL（CLI）**

```bash
curl -X POST \
  -H "api-key: YOUR_API_KEY" \
  -F "file=@/path/to/your/image.heic" \
  https://events-front.mixeder.net/v2/convertion/heictopng/ -o output_image.png
```

***

#### **注意点**

* **APIキーの管理**: APIキーは安全に保管してください。外部に公開されると不正利用のリスクがあります。
* **ファイルサイズ**: ファイルサイズの制限(100MBまで)を確認し、それを超えないようにしてください。
* **エラーハンドリング**: 各サンプルコードにはエラーハンドリングを含めていますが、運用環境に合わせて最適化してください。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.mixeder.net/conversion-api/docs/png-via-heic-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
