JavaScript API統合 – ByByBG ドキュメント
⚡ JavaScript SDK

JavaScript 統合

JavaScriptとFetch APIを使用して画像をアップロードし、ByByBG AI背景削除APIで処理します。

概要

JavaScript背景削除API

JavaScriptを使用することで、最新のWebアプリケーションへ画像アップロードとAI処理を簡単に統合できます。

📤

🤖

🖼️

STEP 1

<input type="file"
id="imageInput">

<button onclick="removeBg()">
    Remove Background
</button>

<div id="result"></div>
STEP 2

Fetch API サンプル

FormDataを使用して画像を送信し、透過PNG画像を取得します。

async function removeBg(){

    const fileInput =
    document.getElementById("imageInput");

    const result =
    document.getElementById("result");

    if(!fileInput.files.length){

        alert("Select image first");

        return;
    }

    const formData = new FormData();

    formData.append(
        "file",
        fileInput.files[0]
    );

    result.innerHTML =
    "Processing...";

    try{

        const response = await fetch(
            "/ajax/remove-bg.php",
            {
                method:"POST",
                body:formData
            }
        );

        if(!response.ok){
            throw new Error();
        }

        const blob =
        await response.blob();

        const url =
        URL.createObjectURL(blob);

        result.innerHTML = `
            <img src="${url}"
            style="max-width:100%;">

            <br><br>

            <a href="${url}"
            download="no-bg.png">
                Download PNG
            </a>
        `;

    }catch{

        result.innerHTML =
        "Something went wrong";

    }
}
FEATURES

推奨機能

SECURITY

重要

ERRORS

Error
Description
401
413
429
500

Pythonへ進む

PythonとByByBG APIを利用した背景削除自動化について学びましょう。