Documentación

Guías, referencias y documentación de la API para las herramientas de DeepAI

¡Lánzate!

Generador de imágenes con IAVolver al inicio ↑
Editor de fotos con IAVolver al inicio ↑
Generador de videos con IA ProVolver al inicio ↑
Website BuilderVolver al inicio ↑
Herramientas adicionalesVolver al inicio ↑
Primeros pasosVolver al inicio ↑

Generador de imágenes con IAVolver al inicio ↑

Este es un generador de imágenes con IA. Crea una imagen desde cero a partir de una descripción de texto.

Punto final: POST https://api.deepai.org/api/text2img

Parámetros
ParámetroTipoObligatorioPor defecto
text text

text — una cadena que describe lo que se va a generar, por ejemplo, «Una noche estrellada sobre un lago tranquilo» o «El retrato de un viejo pirata».

width, height — pasa una cadena, por ejemplo, "256" o "768" (por defecto 512). Usa valores entre 128 y 1536, en múltiplos de 32. Recomendado para imágenes estándar: 1024x576, 1024x720, 512x512, 768x1024, 576x1024. Recomendado para imágenes en HD: 1216x832, 1152x896, 1024x1024, 896x1152, 832x1216. Los valores por encima de ~700 o por debajo de 256 pueden generar resultados extraños.

image_generator_version — «standard» (predeterminado), «hd», «genius» o «super_genius».

resolution — «2k» (por defecto) o «4k». Solo se usa cuando image_generator_version es «super_genius».

genius_preference — «anime», «photography», «graphic» o «cinematic». Solo se usa cuando image_generator_version es «genius».

negative_prompt — una cadena que describe qué hay que eliminar de la imagen; útil para mejorar la calidad y los detalles. Ejemplos: anatomía incorrecta, borrosa, recortada, deformada, desfigurada, duplicada, extremidades de más, dedos fusionados, artefactos JPEG, baja calidad, baja resolución, manos mutadas, fuera del encuadre, firma, texto, marca de agua, pésima calidad.

Ejemplos de Generador de imágenes con IA en cURL

# Example posting a text URL:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/text2img 


# Example posting a local text file:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/text2img 


# Example directly sending a text string:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/text2img 

Ejemplos de Generador de imágenes con IA en Javascript

// Example posting a text URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/text2img', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: "YOUR_TEXT_HERE",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input text (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('text', 'YOUR_TEXT_HERE');

       const resp = await fetch('https://api.deepai.org/api/text2img', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local text file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       formData.append('text', 'YOUR_TEXT_HERE');

       const resp = await fetch('https://api.deepai.org/api/text2img', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example directly sending a text string:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/text2img', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: "YOUR_TEXT_HERE",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()

Ejemplos de Generador de imágenes con IA en Python

# Example posting a text URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/text2img",
    data={
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local text file:

import requests
r = requests.post(
    "https://api.deepai.org/api/text2img",
    data={
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example directly sending a text string:

import requests
r = requests.post(
    "https://api.deepai.org/api/text2img",
    data={
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Generador de imágenes con IA en Ruby

# Example posting a text URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/text2img', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
    }
)
puts r


# Example posting a local text file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/text2img', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
    }
)
puts r


# Example directly sending a text string:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/text2img', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
    }
)
puts r

Ejemplos de Generador de imágenes con IA en Php

// Example posting a text URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/text2img', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local text file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/text2img', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example directly sending a text string:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/text2img', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Generador de imágenes con IA en Go

// Example posting a text URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/text2img"
    payload := map[string]string{
        "text": "YOUR_TEXT_HERE",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local text file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/text2img"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    w.WriteField("text", "YOUR_TEXT_HERE")

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example directly sending a text string:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/text2img"
    payload := map[string]string{
        "text": "YOUR_TEXT_HERE",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Generador de imágenes con IA en Java

// Example posting a text URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"text\": \"YOUR_TEXT_HERE\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/text2img"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local text file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("text", "YOUR_TEXT_HERE")
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/text2img")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}


// Example directly sending a text string:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"text\": \"YOUR_TEXT_HERE\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/text2img"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Ejemplos de Generador de imágenes con IA en C#

// Example posting a text URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            text = "YOUR_TEXT_HERE",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/text2img", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local text file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        form.Add(new StringContent("YOUR_TEXT_HERE"), "text");

        var response = await client.PostAsync("https://api.deepai.org/api/text2img", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example directly sending a text string:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            text = "YOUR_TEXT_HERE",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/text2img", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Generador de imágenes con IA en Swift

// Example posting a text URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/text2img")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "text": "YOUR_TEXT_HERE",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local text file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/text2img")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"text\"\r\n\r\n".data(using: .utf8)!)
body.append("YOUR_TEXT_HERE".data(using: .utf8)!)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()


// Example directly sending a text string:
import Foundation

let url = URL(string: "https://api.deepai.org/api/text2img")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "text": "YOUR_TEXT_HERE",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Generador de imágenes con IA en Kotlin

// Example posting a text URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "text": "YOUR_TEXT_HERE"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/text2img"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local text file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("text", "YOUR_TEXT_HERE")
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/text2img")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}


// Example directly sending a text string:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "text": "YOUR_TEXT_HERE"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/text2img"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}

Ejemplos de Generador de imágenes con IA en Rust

// Example posting a text URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("text", "YOUR_TEXT_HERE");

    let response = client
        .post("https://api.deepai.org/api/text2img")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local text file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .text("text", "YOUR_TEXT_HERE");

    let response = client
        .post("https://api.deepai.org/api/text2img")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example directly sending a text string:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("text", "YOUR_TEXT_HERE");

    let response = client
        .post("https://api.deepai.org/api/text2img")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Generador de imágenes con IA en TypeScript

// Example posting a text URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/text2img', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: 'YOUR_TEXT_HERE',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local text file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('text', 'YOUR_TEXT_HERE');

    const response = await fetch('https://api.deepai.org/api/text2img', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();


// Example directly sending a text string:
interface ApiResponse {
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/text2img', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: 'YOUR_TEXT_HERE',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();

Ejemplos de Generador de imágenes con IA en Dart

// Example posting a text URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/text2img'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'text': 'YOUR_TEXT_HERE',
    }),
  );

  print(response.body);
}


// Example posting a local text file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/text2img'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.fields['text'] = 'YOUR_TEXT_HERE';

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}


// Example directly sending a text string:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/text2img'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'text': 'YOUR_TEXT_HERE',
    }),
  );

  print(response.body);
}

Ejemplos de Generador de imágenes con IA en PowerShell

# Example posting a text URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/text2img `
    -Method Post `
    -Form @{
         text='YOUR_TEXT_HERE' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local text file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/text2img `
    -Method Post `
    -Form @{
         text='YOUR_TEXT_HERE' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example directly sending a text string:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/text2img `
    -Method Post `
    -Form @{
         text='YOUR_TEXT_HERE' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Eliminador de fondoVolver al inicio ↑

Elimina el fondo de una imagen con IA.

Punto final: POST https://api.deepai.org/api/background-remover

Parámetros
ParámetroTipoObligatorioPor defecto
image image

Ejemplos de Eliminador de fondo en cURL

# Example posting a image URL:

curl \
    -F 'image=YOUR_IMAGE_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/background-remover 


# Example posting a local image file:

curl \
    -F 'image=@/path/to/your/file.jpg' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/background-remover 

Ejemplos de Eliminador de fondo en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/background-remover', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: "YOUR_IMAGE_URL",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('image', this.files[0]);

       const resp = await fetch('https://api.deepai.org/api/background-remover', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);

       const resp = await fetch('https://api.deepai.org/api/background-remover', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

Ejemplos de Eliminador de fondo en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/background-remover",
    data={
        'image': 'YOUR_IMAGE_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/background-remover",
    files={
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Eliminador de fondo en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/background-remover', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => 'YOUR_IMAGE_URL',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/background-remover', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => File.new('/path/to/your/file.jpg'),
    }
)
puts r

Ejemplos de Eliminador de fondo en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/background-remover', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/background-remover', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Eliminador de fondo en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/background-remover"
    payload := map[string]string{
        "image": "YOUR_IMAGE_URL",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/background-remover"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Eliminador de fondo en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/background-remover"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/background-remover")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Ejemplos de Eliminador de fondo en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            image = "YOUR_IMAGE_URL",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/background-remover", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        var response = await client.PostAsync("https://api.deepai.org/api/background-remover", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Eliminador de fondo en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/background-remover")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "image": "YOUR_IMAGE_URL",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/background-remover")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Eliminador de fondo en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "image": "YOUR_IMAGE_URL"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/background-remover"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/background-remover")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}

Ejemplos de Eliminador de fondo en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("image", "YOUR_IMAGE_URL");

    let response = client
        .post("https://api.deepai.org/api/background-remover")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .file("image", "/path/to/your/file.jpg")?;

    let response = client
        .post("https://api.deepai.org/api/background-remover")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Eliminador de fondo en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/background-remover', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: 'YOUR_IMAGE_URL',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));

    const response = await fetch('https://api.deepai.org/api/background-remover', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();

Ejemplos de Eliminador de fondo en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/background-remover'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'image': 'YOUR_IMAGE_URL',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/background-remover'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}

Ejemplos de Eliminador de fondo en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/background-remover `
    -Method Post `
    -Form @{
         image='YOUR_IMAGE_URL' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/background-remover `
    -Method Post `
    -Form @{
        image=Get-Item -Path '/path/to/your/file.jpg' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Editor de fotos con IAVolver al inicio ↑

Edita fotos e imágenes con IA.

Punto final: POST https://api.deepai.org/api/image-editor

Parámetros
ParámetroTipoObligatorioPor defecto
image image
text text

image_generator_version — opcional. Usa "genius" o "super_genius" para ediciones de mayor calidad y más detalladas. Por defecto, se usa el editor estándar.

resolution — «2k» (por defecto) o «4k». Solo se usa cuando image_generator_version es «super_genius».

Ejemplos de Editor de fotos con IA en cURL

# Example posting a image URL:

curl \
    -F 'image=YOUR_IMAGE_URL' \
    -F 'text=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/image-editor 


# Example posting a local image file:

curl \
    -F 'image=@/path/to/your/file.jpg' \
    -F 'text=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/image-editor 

Ejemplos de Editor de fotos con IA en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/image-editor', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: "YOUR_IMAGE_URL",
            text: "YOUR_TEXT_HERE",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('image', this.files[0]);
       formData.append('text', 'YOUR_TEXT_HERE');

       const resp = await fetch('https://api.deepai.org/api/image-editor', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);
       formData.append('text', 'YOUR_TEXT_HERE');

       const resp = await fetch('https://api.deepai.org/api/image-editor', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

Ejemplos de Editor de fotos con IA en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/image-editor",
    data={
        'image': 'YOUR_IMAGE_URL',
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/image-editor",
    files={
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    data={
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Editor de fotos con IA en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/image-editor', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => 'YOUR_IMAGE_URL',
        'text' => 'YOUR_TEXT_HERE',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/image-editor', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => File.new('/path/to/your/file.jpg'),
        'text' => 'YOUR_TEXT_HERE',
    }
)
puts r

Ejemplos de Editor de fotos con IA en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/image-editor', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/image-editor', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Editor de fotos con IA en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/image-editor"
    payload := map[string]string{
        "image": "YOUR_IMAGE_URL",
        "text": "YOUR_TEXT_HERE",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/image-editor"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    w.WriteField("text", "YOUR_TEXT_HERE")

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Editor de fotos con IA en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "\"text\": \"YOUR_TEXT_HERE\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/image-editor"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .addFormDataPart("text", "YOUR_TEXT_HERE")
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/image-editor")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Ejemplos de Editor de fotos con IA en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            image = "YOUR_IMAGE_URL",
            text = "YOUR_TEXT_HERE",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/image-editor", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        form.Add(new StringContent("YOUR_TEXT_HERE"), "text");

        var response = await client.PostAsync("https://api.deepai.org/api/image-editor", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Editor de fotos con IA en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/image-editor")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "image": "YOUR_IMAGE_URL",
    "text": "YOUR_TEXT_HERE",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/image-editor")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"text\"\r\n\r\n".data(using: .utf8)!)
body.append("YOUR_TEXT_HERE".data(using: .utf8)!)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Editor de fotos con IA en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "image": "YOUR_IMAGE_URL",
        "text": "YOUR_TEXT_HERE"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/image-editor"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .addFormDataPart("text", "YOUR_TEXT_HERE")
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/image-editor")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}

Ejemplos de Editor de fotos con IA en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("image", "YOUR_IMAGE_URL");
    payload.insert("text", "YOUR_TEXT_HERE");

    let response = client
        .post("https://api.deepai.org/api/image-editor")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .file("image", "/path/to/your/file.jpg")?
        .text("text", "YOUR_TEXT_HERE");

    let response = client
        .post("https://api.deepai.org/api/image-editor")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Editor de fotos con IA en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/image-editor', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: 'YOUR_IMAGE_URL',
            text: 'YOUR_TEXT_HERE',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));
    formData.append('text', 'YOUR_TEXT_HERE');

    const response = await fetch('https://api.deepai.org/api/image-editor', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();

Ejemplos de Editor de fotos con IA en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/image-editor'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'image': 'YOUR_IMAGE_URL',
      'text': 'YOUR_TEXT_HERE',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/image-editor'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  request.fields['text'] = 'YOUR_TEXT_HERE';

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}

Ejemplos de Editor de fotos con IA en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/image-editor `
    -Method Post `
    -Form @{
         image='YOUR_IMAGE_URL' 
         text='YOUR_TEXT_HERE' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/image-editor `
    -Method Post `
    -Form @{
        image=Get-Item -Path '/path/to/your/file.jpg' 
         text='YOUR_TEXT_HERE' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Colorizador de imágenesVolver al inicio ↑

Dale color a tus viejas fotos familiares e imágenes históricas, o revive una película antigua con la coloración.

Punto final: POST https://api.deepai.org/api/colorizer

Parámetros
ParámetroTipoObligatorioPor defecto
image image

Ejemplos de Colorizador de imágenes en cURL

# Example posting a image URL:

curl \
    -F 'image=YOUR_IMAGE_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/colorizer 


# Example posting a local image file:

curl \
    -F 'image=@/path/to/your/file.jpg' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/colorizer 

Ejemplos de Colorizador de imágenes en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/colorizer', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: "YOUR_IMAGE_URL",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('image', this.files[0]);

       const resp = await fetch('https://api.deepai.org/api/colorizer', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);

       const resp = await fetch('https://api.deepai.org/api/colorizer', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

Ejemplos de Colorizador de imágenes en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/colorizer",
    data={
        'image': 'YOUR_IMAGE_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/colorizer",
    files={
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Colorizador de imágenes en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/colorizer', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => 'YOUR_IMAGE_URL',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/colorizer', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => File.new('/path/to/your/file.jpg'),
    }
)
puts r

Ejemplos de Colorizador de imágenes en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/colorizer', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/colorizer', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Colorizador de imágenes en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/colorizer"
    payload := map[string]string{
        "image": "YOUR_IMAGE_URL",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/colorizer"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Colorizador de imágenes en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/colorizer"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/colorizer")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Ejemplos de Colorizador de imágenes en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            image = "YOUR_IMAGE_URL",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/colorizer", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        var response = await client.PostAsync("https://api.deepai.org/api/colorizer", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Colorizador de imágenes en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/colorizer")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "image": "YOUR_IMAGE_URL",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/colorizer")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Colorizador de imágenes en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "image": "YOUR_IMAGE_URL"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/colorizer"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/colorizer")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}

Ejemplos de Colorizador de imágenes en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("image", "YOUR_IMAGE_URL");

    let response = client
        .post("https://api.deepai.org/api/colorizer")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .file("image", "/path/to/your/file.jpg")?;

    let response = client
        .post("https://api.deepai.org/api/colorizer")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Colorizador de imágenes en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/colorizer', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: 'YOUR_IMAGE_URL',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));

    const response = await fetch('https://api.deepai.org/api/colorizer', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();

Ejemplos de Colorizador de imágenes en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/colorizer'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'image': 'YOUR_IMAGE_URL',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/colorizer'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}

Ejemplos de Colorizador de imágenes en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/colorizer `
    -Method Post `
    -Form @{
         image='YOUR_IMAGE_URL' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/colorizer `
    -Method Post `
    -Form @{
        image=Get-Item -Path '/path/to/your/file.jpg' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

SuperresoluciónVolver al inicio ↑

La API de superresolución usa el aprendizaje automático para aclarar, enfocar y aumentar la resolución de la foto sin perder su contenido ni sus características distintivas. Lamentablemente, las imágenes borrosas son muy comunes y representan un problema tanto para los profesionales como para los aficionados. La superresolución usa técnicas de aprendizaje automático para aumentar la resolución de las imágenes en una fracción de segundo.

Punto final: POST https://api.deepai.org/api/torch-srgan

Parámetros
ParámetroTipoObligatorioPor defecto
image image

Ejemplos de Superresolución en cURL

# Example posting a image URL:

curl \
    -F 'image=YOUR_IMAGE_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/torch-srgan 


# Example posting a local image file:

curl \
    -F 'image=@/path/to/your/file.jpg' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/torch-srgan 

Ejemplos de Superresolución en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/torch-srgan', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: "YOUR_IMAGE_URL",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('image', this.files[0]);

       const resp = await fetch('https://api.deepai.org/api/torch-srgan', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);

       const resp = await fetch('https://api.deepai.org/api/torch-srgan', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

Ejemplos de Superresolución en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/torch-srgan",
    data={
        'image': 'YOUR_IMAGE_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/torch-srgan",
    files={
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Superresolución en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/torch-srgan', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => 'YOUR_IMAGE_URL',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/torch-srgan', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => File.new('/path/to/your/file.jpg'),
    }
)
puts r

Ejemplos de Superresolución en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/torch-srgan', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/torch-srgan', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Superresolución en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/torch-srgan"
    payload := map[string]string{
        "image": "YOUR_IMAGE_URL",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/torch-srgan"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Superresolución en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/torch-srgan"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/torch-srgan")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Ejemplos de Superresolución en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            image = "YOUR_IMAGE_URL",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/torch-srgan", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        var response = await client.PostAsync("https://api.deepai.org/api/torch-srgan", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Superresolución en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/torch-srgan")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "image": "YOUR_IMAGE_URL",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/torch-srgan")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Superresolución en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "image": "YOUR_IMAGE_URL"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/torch-srgan"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/torch-srgan")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}

Ejemplos de Superresolución en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("image", "YOUR_IMAGE_URL");

    let response = client
        .post("https://api.deepai.org/api/torch-srgan")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .file("image", "/path/to/your/file.jpg")?;

    let response = client
        .post("https://api.deepai.org/api/torch-srgan")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Superresolución en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/torch-srgan', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: 'YOUR_IMAGE_URL',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));

    const response = await fetch('https://api.deepai.org/api/torch-srgan', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();

Ejemplos de Superresolución en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/torch-srgan'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'image': 'YOUR_IMAGE_URL',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/torch-srgan'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}

Ejemplos de Superresolución en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/torch-srgan `
    -Method Post `
    -Form @{
         image='YOUR_IMAGE_URL' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/torch-srgan `
    -Method Post `
    -Form @{
        image=Get-Item -Path '/path/to/your/file.jpg' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Waifu2xVolver al inicio ↑

Waifu2x es un algoritmo que aumenta la resolución de las imágenes mientras reduce el ruido en ellas. Su nombre viene del estilo artístico de anime conocido como «waifu», con el que se entrenó en gran parte. Aunque los waifus constituían la mayor parte de los datos de entrenamiento, esta API de Waifu2x sigue funcionando bien con fotografías y otros tipos de imágenes. Puedes usar Waifu2x para duplicar el tamaño de tus imágenes y, al mismo tiempo, reducir el ruido.

Punto final: POST https://api.deepai.org/api/waifu2x

Parámetros
ParámetroTipoObligatorioPor defecto
image image

Ejemplos de Waifu2x en cURL

# Example posting a image URL:

curl \
    -F 'image=YOUR_IMAGE_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/waifu2x 


# Example posting a local image file:

curl \
    -F 'image=@/path/to/your/file.jpg' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/waifu2x 

Ejemplos de Waifu2x en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/waifu2x', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: "YOUR_IMAGE_URL",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('image', this.files[0]);

       const resp = await fetch('https://api.deepai.org/api/waifu2x', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);

       const resp = await fetch('https://api.deepai.org/api/waifu2x', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

Ejemplos de Waifu2x en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/waifu2x",
    data={
        'image': 'YOUR_IMAGE_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/waifu2x",
    files={
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Waifu2x en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/waifu2x', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => 'YOUR_IMAGE_URL',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/waifu2x', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => File.new('/path/to/your/file.jpg'),
    }
)
puts r

Ejemplos de Waifu2x en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/waifu2x', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/waifu2x', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Waifu2x en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/waifu2x"
    payload := map[string]string{
        "image": "YOUR_IMAGE_URL",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/waifu2x"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Waifu2x en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/waifu2x"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/waifu2x")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Ejemplos de Waifu2x en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            image = "YOUR_IMAGE_URL",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/waifu2x", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        var response = await client.PostAsync("https://api.deepai.org/api/waifu2x", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Waifu2x en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/waifu2x")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "image": "YOUR_IMAGE_URL",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/waifu2x")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Waifu2x en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "image": "YOUR_IMAGE_URL"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/waifu2x"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/waifu2x")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}

Ejemplos de Waifu2x en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("image", "YOUR_IMAGE_URL");

    let response = client
        .post("https://api.deepai.org/api/waifu2x")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .file("image", "/path/to/your/file.jpg")?;

    let response = client
        .post("https://api.deepai.org/api/waifu2x")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Waifu2x en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/waifu2x', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: 'YOUR_IMAGE_URL',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));

    const response = await fetch('https://api.deepai.org/api/waifu2x', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();

Ejemplos de Waifu2x en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/waifu2x'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'image': 'YOUR_IMAGE_URL',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/waifu2x'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}

Ejemplos de Waifu2x en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/waifu2x `
    -Method Post `
    -Form @{
         image='YOUR_IMAGE_URL' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/waifu2x `
    -Method Post `
    -Form @{
        image=Get-Item -Path '/path/to/your/file.jpg' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Ampliación creativaVolver al inicio ↑

Punto final: POST https://api.deepai.org/api/creative-upscale

Parámetros
ParámetroTipoObligatorioPor defecto
image image

Ejemplos de Ampliación creativa en cURL

# Example posting a image URL:

curl \
    -F 'image=YOUR_IMAGE_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/creative-upscale 


# Example posting a local image file:

curl \
    -F 'image=@/path/to/your/file.jpg' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/creative-upscale 

Ejemplos de Ampliación creativa en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/creative-upscale', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: "YOUR_IMAGE_URL",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('image', this.files[0]);

       const resp = await fetch('https://api.deepai.org/api/creative-upscale', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);

       const resp = await fetch('https://api.deepai.org/api/creative-upscale', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

Ejemplos de Ampliación creativa en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/creative-upscale",
    data={
        'image': 'YOUR_IMAGE_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/creative-upscale",
    files={
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Ampliación creativa en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/creative-upscale', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => 'YOUR_IMAGE_URL',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/creative-upscale', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'image' => File.new('/path/to/your/file.jpg'),
    }
)
puts r

Ejemplos de Ampliación creativa en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/creative-upscale', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/creative-upscale', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Ampliación creativa en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/creative-upscale"
    payload := map[string]string{
        "image": "YOUR_IMAGE_URL",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/creative-upscale"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Ampliación creativa en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/creative-upscale"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/creative-upscale")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Ejemplos de Ampliación creativa en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            image = "YOUR_IMAGE_URL",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/creative-upscale", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        var response = await client.PostAsync("https://api.deepai.org/api/creative-upscale", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Ampliación creativa en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/creative-upscale")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "image": "YOUR_IMAGE_URL",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/creative-upscale")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Ampliación creativa en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "image": "YOUR_IMAGE_URL"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/creative-upscale"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/creative-upscale")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}

Ejemplos de Ampliación creativa en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("image", "YOUR_IMAGE_URL");

    let response = client
        .post("https://api.deepai.org/api/creative-upscale")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .file("image", "/path/to/your/file.jpg")?;

    let response = client
        .post("https://api.deepai.org/api/creative-upscale")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Ampliación creativa en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/creative-upscale', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            image: 'YOUR_IMAGE_URL',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));

    const response = await fetch('https://api.deepai.org/api/creative-upscale', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();

Ejemplos de Ampliación creativa en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/creative-upscale'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'image': 'YOUR_IMAGE_URL',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/creative-upscale'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}

Ejemplos de Ampliación creativa en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/creative-upscale `
    -Method Post `
    -Form @{
         image='YOUR_IMAGE_URL' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/creative-upscale `
    -Method Post `
    -Form @{
        image=Get-Item -Path '/path/to/your/file.jpg' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Reemplazar imagenVolver al inicio ↑

Reemplaza y edita objetos en imágenes con IA.

Punto final: POST https://api.deepai.org/api/image-replace

Parámetros
ParámetroTipoObligatorioPor defecto
image image
mask image
text text

Ejemplos de Reemplazar imagen en cURL

# Example posting a image URL:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -F 'mask=YOUR_IMAGE_URL' \
    -F 'image=YOUR_IMAGE_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/image-replace 


# Example posting a local image file:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -F 'mask=@/path/to/your/file.jpg' \
    -F 'image=@/path/to/your/file.jpg' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/image-replace 


# Example directly sending a text string:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -F 'mask=YOUR_TEXT_HERE' \
    -F 'image=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/image-replace 

Ejemplos de Reemplazar imagen en Javascript

// Example posting a image URL:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/image-replace', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: "YOUR_TEXT_HERE",
            mask: "YOUR_IMAGE_URL",
            image: "YOUR_IMAGE_URL",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()


// Example posting file picker input image (Browser only):
document.getElementById('yourFileInputId').addEventListener('change', async function() {
       const formData = new FormData();
       formData.append('text', 'YOUR_TEXT_HERE');
       formData.append('mask', this.files[0]);
       formData.append('image', this.files[1]);

       const resp = await fetch('https://api.deepai.org/api/image-replace', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example posting a local image file (Node.js only):
const fs = require('fs');
(async function() {
       const formData = new FormData();
       formData.append('text', 'YOUR_TEXT_HERE');
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('mask', jpgFileStream);
       const jpgFileStream = fs.createReadStream("/path/to/your/file.jpg");
       formData.append('image', jpgFileStream);

       const resp = await fetch('https://api.deepai.org/api/image-replace', {
           method: 'POST',
           headers: {
               'api-key': 'YOUR_API_KEY'
           },
           body: formData
       });

       const data = await resp.json();
       console.log(data);
});

// Example directly sending a text string:
(async function() {
    const resp = await fetch('https://api.deepai.org/api/image-replace', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: "YOUR_TEXT_HERE",
            mask: "YOUR_TEXT_HERE",
            image: "YOUR_TEXT_HERE",
        })
    });
    
    const data = await resp.json();
    console.log(data);
})()

Ejemplos de Reemplazar imagen en Python

# Example posting a image URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/image-replace",
    data={
        'text': 'YOUR_TEXT_HERE',
        'mask': 'YOUR_IMAGE_URL',
        'image': 'YOUR_IMAGE_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local image file:

import requests
r = requests.post(
    "https://api.deepai.org/api/image-replace",
    files={
        'mask': open('/path/to/your/file.jpg', 'rb'),
        'image': open('/path/to/your/file.jpg', 'rb'),
    },
    data={
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example directly sending a text string:

import requests
r = requests.post(
    "https://api.deepai.org/api/image-replace",
    data={
        'text': 'YOUR_TEXT_HERE',
        'mask': 'YOUR_TEXT_HERE',
        'image': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Ejemplos de Reemplazar imagen en Ruby

# Example posting a image URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/image-replace', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
        'mask' => 'YOUR_IMAGE_URL',
        'image' => 'YOUR_IMAGE_URL',
    }
)
puts r


# Example posting a local image file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/image-replace', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
        'mask' => File.new('/path/to/your/file.jpg'),
        'image' => File.new('/path/to/your/file.jpg'),
    }
)
puts r


# Example directly sending a text string:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/image-replace', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
        'mask' => 'YOUR_TEXT_HERE',
        'image' => 'YOUR_TEXT_HERE',
    }
)
puts r

Ejemplos de Reemplazar imagen en Php

// Example posting a image URL:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
        [
            'name'     => 'mask',
            'contents' => 'YOUR_IMAGE_URL'
        ],
        [
            'name'     => 'image',
            'contents' => 'YOUR_IMAGE_URL'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/image-replace', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example posting a local image file:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
        [
            'name'     => 'mask',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
        [
            'name'     => 'image',
            'contents' => Utils::tryFopen('/path/to/your/file.jpg', 'r')
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/image-replace', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>


// Example directly sending a text string:
<?php
require 'vendor/autoload.php'; // Ensure you have Guzzle installed (composer require guzzlehttp/guzzle)

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
    'api-key' => 'YOUR_API_KEY'
];
$options = [
    'multipart' => [
        [
            'name'     => 'text',
            'contents' => 'YOUR_TEXT_HERE'
        ],
        [
            'name'     => 'mask',
            'contents' => 'YOUR_TEXT_HERE'
        ],
        [
            'name'     => 'image',
            'contents' => 'YOUR_TEXT_HERE'
        ],
    ]
];
$request = new GuzzleHttp\Psr7\Request('POST', 'https://api.deepai.org/api/image-replace', $headers);
try {
    $res = $client->sendAsync($request, $options)->wait();
    echo $res->getBody();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Ejemplos de Reemplazar imagen en Go

// Example posting a image URL:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/image-replace"
    payload := map[string]string{
        "text": "YOUR_TEXT_HERE",
        "mask": "YOUR_IMAGE_URL",
        "image": "YOUR_IMAGE_URL",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example posting a local image file:
package main

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    url := "https://api.deepai.org/api/image-replace"

    var b bytes.Buffer
    w := multipart.NewWriter(&b)

    w.WriteField("text", "YOUR_TEXT_HERE")

    maskFile, _ := os.Open("/path/to/your/file.jpg")
    defer maskFile.Close()
    maskWriter, _ := w.CreateFormFile("mask", "file.jpg")
    io.Copy(maskWriter, maskFile)

    imageFile, _ := os.Open("/path/to/your/file.jpg")
    defer imageFile.Close()
    imageWriter, _ := w.CreateFormFile("image", "file.jpg")
    io.Copy(imageWriter, imageFile)

    if err := w.Close(); err != nil {
        panic(err)
    }

    req, _ := http.NewRequest("POST", url, &b)
    req.Header.Set("Content-Type", w.FormDataContentType())
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}


// Example directly sending a text string:
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://api.deepai.org/api/image-replace"
    payload := map[string]string{
        "text": "YOUR_TEXT_HERE",
        "mask": "YOUR_TEXT_HERE",
        "image": "YOUR_TEXT_HERE",
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("api-key", "YOUR_API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Ejemplos de Reemplazar imagen en Java

// Example posting a image URL:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"text\": \"YOUR_TEXT_HERE\"" +
            "\"mask\": \"YOUR_IMAGE_URL\"" +
            "\"image\": \"YOUR_IMAGE_URL\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/image-replace"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}


// Example posting a local image file:
// Add to build.gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0'
import okhttp3.*;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("text", "YOUR_TEXT_HERE")
            .addFormDataPart("mask", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .addFormDataPart("image", "file.jpg", RequestBody.create(new File("/path/to/your/file.jpg"), MediaType.parse("application/octet-stream")))
            .build();

        Request request = new Request.Builder()
            .url("https://api.deepai.org/api/image-replace")
            .addHeader("api-key", "YOUR_API_KEY")
            .post(requestBody)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}


// Example directly sending a text string:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        String json = "{" +
            "\"text\": \"YOUR_TEXT_HERE\"" +
            "\"mask\": \"YOUR_TEXT_HERE\"" +
            "\"image\": \"YOUR_TEXT_HERE\"" +
            "}";

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.deepai.org/api/image-replace"))
            .header("Content-Type", "application/json")
            .header("api-key", "YOUR_API_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Ejemplos de Reemplazar imagen en C#

// Example posting a image URL:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            text = "YOUR_TEXT_HERE",
            mask = "YOUR_IMAGE_URL",
            image = "YOUR_IMAGE_URL",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/image-replace", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example posting a local image file:
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        using var form = new MultipartFormDataContent();

        form.Add(new StringContent("YOUR_TEXT_HERE"), "text");

        var maskStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(maskStream), "mask", "file.jpg");

        var imageStream = File.OpenRead("/path/to/your/file.jpg");
        form.Add(new StreamContent(imageStream), "image", "file.jpg");

        var response = await client.PostAsync("https://api.deepai.org/api/image-replace", form);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}


// Example directly sending a text string:
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("api-key", "YOUR_API_KEY");

        var payload = new
        {
            text = "YOUR_TEXT_HERE",
            mask = "YOUR_TEXT_HERE",
            image = "YOUR_TEXT_HERE",
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync("https://api.deepai.org/api/image-replace", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}

Ejemplos de Reemplazar imagen en Swift

// Example posting a image URL:
import Foundation

let url = URL(string: "https://api.deepai.org/api/image-replace")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "text": "YOUR_TEXT_HERE",
    "mask": "YOUR_IMAGE_URL",
    "image": "YOUR_IMAGE_URL",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

// Keep the program running for async request
RunLoop.main.run()


// Example posting a local image file:
import Foundation

let url = URL(string: "https://api.deepai.org/api/image-replace")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()

body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"text\"\r\n\r\n".data(using: .utf8)!)
body.append("YOUR_TEXT_HERE".data(using: .utf8)!)
body.append("\r\n".data(using: .utf8)!)

let maskData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"mask\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(maskData)
body.append("\r\n".data(using: .utf8)!)

let imageData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/your/file.jpg"))
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"image\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(imageData)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()


// Example directly sending a text string:
import Foundation

let url = URL(string: "https://api.deepai.org/api/image-replace")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "api-key")

let payload: [String: Any] = [
    "text": "YOUR_TEXT_HERE",
    "mask": "YOUR_TEXT_HERE",
    "image": "YOUR_TEXT_HERE",
]

request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()

RunLoop.main.run()

Ejemplos de Reemplazar imagen en Kotlin

// Example posting a image URL:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "text": "YOUR_TEXT_HERE",
        "mask": "YOUR_IMAGE_URL",
        "image": "YOUR_IMAGE_URL"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/image-replace"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}


// Example posting a local image file:
// Add to build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

fun main() {
    val client = OkHttpClient()

    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("text", "YOUR_TEXT_HERE")
        .addFormDataPart("mask", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .addFormDataPart("image", "file.jpg", File("/path/to/your/file.jpg").asRequestBody("application/octet-stream".toMediaType()))
        .build()

    val request = Request.Builder()
        .url("https://api.deepai.org/api/image-replace")
        .addHeader("api-key", "YOUR_API_KEY")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}


// Example directly sending a text string:
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val client = HttpClient.newHttpClient()

    val json = """{
        "text": "YOUR_TEXT_HERE",
        "mask": "YOUR_TEXT_HERE",
        "image": "YOUR_TEXT_HERE"
    }"""

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.deepai.org/api/image-replace"))
        .header("Content-Type", "application/json")
        .header("api-key", "YOUR_API_KEY")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build()

    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
}

Ejemplos de Reemplazar imagen en Rust

// Example posting a image URL:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("text", "YOUR_TEXT_HERE");
    payload.insert("mask", "YOUR_IMAGE_URL");
    payload.insert("image", "YOUR_IMAGE_URL");

    let response = client
        .post("https://api.deepai.org/api/image-replace")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example posting a local image file:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }

use reqwest::multipart;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let form = multipart::Form::new()
        .text("text", "YOUR_TEXT_HERE")
        .file("mask", "/path/to/your/file.jpg")?
        .file("image", "/path/to/your/file.jpg")?;

    let response = client
        .post("https://api.deepai.org/api/image-replace")
        .header("api-key", "YOUR_API_KEY")
        .multipart(form)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}


// Example directly sending a text string:
// Add to Cargo.toml: reqwest = { version = "0.11", features = ["json", "multipart"] }
// tokio = { version = "1", features = ["full"] }
// serde_json = "1"

use reqwest::header::HeaderMap;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert("api-key", "YOUR_API_KEY".parse()?);

    let mut payload = HashMap::new();
    payload.insert("text", "YOUR_TEXT_HERE");
    payload.insert("mask", "YOUR_TEXT_HERE");
    payload.insert("image", "YOUR_TEXT_HERE");

    let response = client
        .post("https://api.deepai.org/api/image-replace")
        .headers(headers)
        .json(&payload)
        .send()
        .await?;

    println!("{}", response.text().await?);
    Ok(())
}

Ejemplos de Reemplazar imagen en TypeScript

// Example posting a image URL:
interface ApiResponse {
    // Define your response type here
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/image-replace', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: 'YOUR_TEXT_HERE',
            mask: 'YOUR_IMAGE_URL',
            image: 'YOUR_IMAGE_URL',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();


// Example posting a local image file (Node.js with form-data package):
// npm install form-data
import * as fs from 'fs';
import FormData from 'form-data';

interface ApiResponse {
    [key: string]: unknown;
}

async function uploadFile(): Promise<ApiResponse> {
    const formData = new FormData();
    formData.append('text', 'YOUR_TEXT_HERE');
    formData.append('mask', fs.createReadStream('/path/to/your/file.jpg'));
    formData.append('image', fs.createReadStream('/path/to/your/file.jpg'));

    const response = await fetch('https://api.deepai.org/api/image-replace', {
        method: 'POST',
        headers: {
            ...formData.getHeaders(),
            'api-key': 'YOUR_API_KEY'
        },
        body: formData as unknown as BodyInit
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

uploadFile();


// Example directly sending a text string:
interface ApiResponse {
    [key: string]: unknown;
}

async function callApi(): Promise<ApiResponse> {
    const response = await fetch('https://api.deepai.org/api/image-replace', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({
            text: 'YOUR_TEXT_HERE',
            mask: 'YOUR_TEXT_HERE',
            image: 'YOUR_TEXT_HERE',
        })
    });

    const data: ApiResponse = await response.json();
    console.log(data);
    return data;
}

callApi();

Ejemplos de Reemplazar imagen en Dart

// Example posting a image URL:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/image-replace'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'text': 'YOUR_TEXT_HERE',
      'mask': 'YOUR_IMAGE_URL',
      'image': 'YOUR_IMAGE_URL',
    }),
  );

  print(response.body);
}


// Example posting a local image file:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://api.deepai.org/api/image-replace'),
  );

  request.headers['api-key'] = 'YOUR_API_KEY';

  request.fields['text'] = 'YOUR_TEXT_HERE';

  request.files.add(
    await http.MultipartFile.fromPath('mask', '/path/to/your/file.jpg'),
  );

  request.files.add(
    await http.MultipartFile.fromPath('image', '/path/to/your/file.jpg'),
  );

  var response = await request.send();
  var responseBody = await response.stream.bytesToString();
  print(responseBody);
}


// Example directly sending a text string:
// Add to pubspec.yaml: http: ^1.1.0

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final response = await http.post(
    Uri.parse('https://api.deepai.org/api/image-replace'),
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY',
    },
    body: jsonEncode({
      'text': 'YOUR_TEXT_HERE',
      'mask': 'YOUR_TEXT_HERE',
      'image': 'YOUR_TEXT_HERE',
    }),
  );

  print(response.body);
}

Ejemplos de Reemplazar imagen en PowerShell

# Example posting a image URL:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/image-replace `
    -Method Post `
    -Form @{
         text='YOUR_TEXT_HERE' 
         mask='YOUR_IMAGE_URL' 
         image='YOUR_IMAGE_URL' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example posting a local image file:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/image-replace `
    -Method Post `
    -Form @{
         text='YOUR_TEXT_HERE' 
        mask=Get-Item -Path '/path/to/your/file.jpg' 
        image=Get-Item -Path '/path/to/your/file.jpg' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

# Example directly sending a text string:

$r = Invoke-WebRequest `
    -Uri https://api.deepai.org/api/image-replace `
    -Method Post `
    -Form @{
         text='YOUR_TEXT_HERE' 
         mask='YOUR_TEXT_HERE' 
         image='YOUR_TEXT_HERE' 
    } `
    -Headers @{
        'api-key'='YOUR_API_KEY' 
    } 
$r.Content

Por favor, regístrate o inicia sesión con tus datos

O inicia sesión con tu correo electrónico
Ingresa tu contraseña
Vuelve a ingresar la contraseña

¿Olvidaste tu contraseña? Haz clic aquí para restablecer
¡Éxito!
Icono de error Se produjo un error

Iniciar sesión con Google

×

Usa tu cuenta de Google para iniciar sesión en DeepAI

×
Pro

Considera usar DeepAI Pro