Удалите фон любого изображения
одним вызовом API
Технология искусственного интеллекта, специализирующаяся на удалении
фона, стала проще, чем когда-либо прежде, с помощью нашего API. Всего
несколькими строками кода вы можете внедрить эту технологию в свое
приложение.
Получить API
bash
nodejs
python
php
java
.net
objective-c
swift
curl -H 'APIKEY: INSERT_YOUR_API_KEY_HERE' \
-F 'file=@/path/to/file.jpg' \
-f 'https://api.ba-la.ru/api/remove' \
-o response.json
import requests
response = requests.post(
'https://api.ba-la.ru/api/remove',
files={'mediaFile': open('INSERT_YOUR_FILE_PATH_HERE', 'rb')},
headers={'api-key': 'INSERT_YOUR_API_KEY_HERE'},
)
//response.content
<?php
$ch = curl_init("https://api.ba-la.ru/api/remove");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mediaFile' => curl_file_create("INSERT_YOUR_IMAGE_PATH_HERE", 'image/jpeg', 'mediaFile')));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('api-key: INSERT_YOUR_API_KEY_HERE'));
ob_start();
curl_exec($ch);
$value = ob_get_contents();
ob_end_clean();
curl_close($ch);
echo $value; //JSON OUTPUT
using (var client = new HttpClient())
using (var formData = new MultipartFormDataContent())
{
formData.Headers.Add("api-key", "INSERT_YOUR_API_KEY_HERE");
formData.Add(new ByteArrayContent(File.ReadAllBytes("/path/to/file.jpg")), "mediaFile", "file.jpg");
var response = client.PostAsync("https://api.ba-la.ru/api/remove", formData).Result;
if(response.IsSuccessStatusCode) {
//todo: Handle your logic
} else {
//todo: Handle your logic
}
}
NSURL *fileUrl = [NSBundle.mainBundle URLForResource:@"file" withExtension:@"jpg"];
NSData *data = [NSData dataWithContentsOfURL:fileUrl];
if (!data) {
return;
}
AFHTTPSessionManager *manager =
[[AFHTTPSessionManager alloc] initWithSessionConfiguration:
NSURLSessionConfiguration.defaultSessionConfiguration];
manager.responseSerializer = [AFImageResponseSerializer serializer];
[manager.requestSerializer setValue:@"INSERT_YOUR_API_KEY_HERE"
forHTTPHeaderField:@"api-key"];
NSURLSessionDataTask *dataTask = [manager
POST:@"https://api.ba-la.ru/api/remove"
parameters:nil
constructingBodyWithBlock:^(id _Nonnull formData) {
[formData appendPartWithFileData:data
name:@"mediaFile"
fileName:@"file.jpg"
mimeType:@"image/jpeg"];
}
progress:nil
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// Handle your logic
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// Handle your logic
}];
[dataTask resume];
File file = new File("INSERT_YOUR_FILE__HERE");
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://api.ba-la.ru/api/remove");
httpPost.setHeader("api-key", "INSERT_YOUR_API_KEY_HERE");
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.addBinaryBody("mediaFile", file);
httpPost.setEntity(multipartEntityBuilder.build());
try (CloseableHttpResponse response = client.execute(httpPost)){
if (response.getStatusLine().getStatusCode() == HttpStatusCode.OK) {
String responseAsString = EntityUtils.toString(response.getEntity());
}
} catch (IOException e) {
e.printStackTrace();
}
var request = require('request');
var fs = require('fs');
request.post({
url: 'https://api.ba-la.ru/api/remove',
formData: {
mediaFile: fs.createReadStream('INSERT_YOUR_FILE_PATH_HERE')
},
headers: {
'api-key': 'INSERT_YOUR_API_KEY_HERE'
},
encoding: null
}, function(error, response, body) {
// console.log(response);
});
guard let fileUrl = Bundle.main.url(forResource: "file", withExtension: "jpg"),
let data = try? Data(contentsOf: fileUrl)
else { return false }
struct HTTPBinResponse: Decodable { let url: String }
AF.upload(
multipartFormData: { builder in
builder.append(
data,
withName: "mediaFile",
fileName: "file.jpg",
mimeType: "image/jpeg"
)
},
to: URL(string: "https://api.ba-la.ru/api/remove")!,
headers: [
"api-key": "INSERT_YOUR_API_KEY_HERE"
]
).responseDecodable(of: HTTPBinResponse.self) { imageResponse in
guard let imageData = imageResponse.data,
let image = UIImage(data: imageData)
else { return }
self.imageView.image = image
}