API Endpoint Access URL
https://api.pixlab.io/facelandmarks
Get Your API Key & Try FACELANDMARKS Now ↗Description
Utilize the FACELANDMARKS API endpoint to detect and extract facial landmarks, along with their corresponding rectangle coordinates. This functionality can be integrated with other API endpoints, including CROP, MOGRIFY, and MERGE, to facilitate advanced face processing. The output will include the rectangle coordinates and extracted facial shapes for each detected face. Several complementary API endpoints are available, such as crop for face extraction, drawrectangles for face annotation, and mogrify for content redaction.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. |
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
POST Request Body
If you plan to use POST instead of a simple GET request:
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
if you want to upload your media file directly (refer to the REST API code samples or The PixLab Github Repository↗ for a working example). If you are using JSON, then the media file must be already uploaded somewhere. Call store if you want to upload an image before invoking this endpoint.
HTTP Response
application/json
.This command always return a JSON object after each call. The field of interest here is the faces array which hold the rectangle & landmarks coordinates for each detected face. The following are the JSON fields returned in response body:
Fields | Type | Description |
---|---|---|
status | Integer | Status code 200 indicates success, any other code indicates failure. |
faces | Array | JSON array holding the rectangle & landmarks coordinates (See below for fields). |
error | String | Error message if status != 200. |
The following are the object fields returned for each detected face in the
faces
array defined above:Fields | Type | Description |
---|---|---|
rectangle | Array | JSON array holding the rectangle coordinates for this face (See below). |
landmarks | Array | JSON array holding the landmarks coordinates for this face (See below). |
The following are the object fields returned in each
rectangle
array, member of the faces
array defined above:Fields | Type | Description |
---|---|---|
face_id | Integer | Detected face ID. |
left | Integer | Rectangle left coordinate: X. |
top | Integer | Rectangle top coordinate: Y. |
width | Integer | Rectangle width. |
height | Integer | Rectangle height. |
The following are the object fields returned in each
landmarks
array, member of the faces
array defined above:Fields | Type | Description |
---|---|---|
nose | Array | Nose Tip coordinates in the form [x: Integer , y: Integer ]. |
nose_bottom_left | Array | Nose bottom left coordinates in the form [x: Integer , y: Integer ]. |
nose_bottom_right | Array | Nose bottom right coordinates in the form [x: Integer , y: Integer ]. |
mouth_left | Array | left most coordinates of the mouth in the form [x: Integer , y: Integer ]. |
mouth_right | Array | Right most coordinates of the mouth in the form [x: Integer , y: Integer ]. |
bottom_lip | Array | Bottom Lip coordinates in the form [x: Integer , y: Integer ]. |
top_lip | Array | Top Lip coordinates in the form [x: Integer , y: Integer ]. |
chin | Array | Chin coordinates in the form [x: Integer , y: Integer ]. |
eye | Array | Array holding the coordinates of the region surrounding the eyes. These includes:
|
bone | Array | Array holding the coordinates of some regions of the bone. These includes:
|
- For additional processing, feel free to adjust these coordinates for the next command such as crop for face extraction, drawrectangles for marking faces, mogrify and merge to mimic the Snapchat filters effects (refer to the REST API code samples for a concrete example).
- If you need additional landmarks coordinates, please fill an API feature request ticket from the support tab of your dashboard ↗.
Code Samples
import requests
import json
from typing import List, Dict, Any
def smart_resize(img: str, width: int, height: int, key: str) -> str:
"""Resize an image using smartresize."""
params = {
'img': img,
'key': key,
'width': width,
'height': height
}
response = requests.get('https://api.pixlab.io/smartresize', params=params)
response.raise_for_status()
reply = response.json()
if reply['status'] != 200:
raise Exception(reply['error'])
return reply['link']
def apply_snapchat_filters(
img: str,
key: str,
draw_crown: bool = False,
flower: str = 'http://pixlab.xyz/images/flower_crown.png',
dog_left_ear: str = 'http://pixlab.xyz/images/dog_left_ear.png',
dog_right_ear: str = 'http://pixlab.xyz/images/dog_right_ear.png',
dog_nose: str = 'http://pixlab.xyz/images/dog_nose.png'
) -> str:
"""Apply Snapchat-like filters to an image."""
# Detect face landmarks
response = requests.get(
'https://api.pixlab.io/facelandmarks',
params={'img': img, 'key': key}
)
response.raise_for_status()
reply = response.json()
if reply['status'] != 200:
raise Exception(reply['error'])
faces = reply.get('faces', [])
if not faces:
raise Exception("No faces were detected")
print(f"{len(faces)} faces were detected")
coordinates: List[Dict[str, Any]] = []
for face in faces:
cord = face['rectangle']
landmarks = face['landmarks']
if draw_crown:
fit_crown = smart_resize(
flower,
20 + cord['width'],
0,
key
)
coordinates.append({
'img': fit_crown,
'x': landmarks['bone']['outer_left']['x'],
'y': landmarks['bone']['outer_left']['y']
})
else:
coordinates.extend([
{
'img': smart_resize(dog_left_ear, cord['width']//2, cord['height']//2, key),
'x': landmarks['bone']['outer_left']['x'],
'y': landmarks['bone']['outer_left']['y']
},
{
'img': smart_resize(dog_right_ear, cord['width']//2, cord['height']//2, key),
'x': landmarks['bone']['outer_right']['x'],
'y': landmarks['bone']['outer_right']['y']
},
{
'img': smart_resize(dog_nose, cord['width']//2, cord['height']//2, key),
'x': landmarks['nose']['x'] - 18,
'y': landmarks['nose']['y'] - 10
}
])
draw_crown = not draw_crown
# Perform composite operation
response = requests.post(
'https://api.pixlab.io/merge',
headers={'Content-Type': 'application/json'},
data=json.dumps({
'src': img,
'key': key,
'cord': coordinates
})
)
response.raise_for_status()
reply = response.json()
if reply['status'] != 200:
raise Exception(reply['error'])
return reply['link']
if __name__ == "__main__":
# Configuration
IMG_URL = 'https://trekkerscrapbook.files.wordpress.com/2013/09/face-08.jpg'
API_KEY = 'My_PIXLAB_API_KEY'
DRAW_CROWN = False
try:
result_url = apply_snapchat_filters(IMG_URL, API_KEY, DRAW_CROWN)
print(f"Snap Filter Effect: {result_url}")
except Exception as e:
print(f"Error: {e}")
// Target image to composite stuff on. Must contain at least one face.
const img = 'https://trekkerscrapbook.files.wordpress.com/2013/09/face-08.jpg';
// The flower crown.
const flower = 'http://pixlab.xyz/images/flower_crown.png';
// The dog parts: Left & right ears, nose & optionally the tongue
const dog_left_ear = 'http://pixlab.xyz/images/dog_left_ear.png';
const dog_right_ear = 'http://pixlab.xyz/images/dog_right_ear.png';
const dog_nose = 'http://pixlab.xyz/images/dog_nose.png';
const dog_tongue = 'http://pixlab.xyz/images/dog_tongue.png';
// Your PixLab API key
const key = 'My_PIXLAB_API_KEY';
// If set to true then composite the flower crown. Otherwise, composite the dog stuff.
let draw_crown = false;
// Resize an image (Dog parts or the flower crown) to fit the face dimension using smartresize.
async function smart_resize(img, width, height) {
console.log("Resizing images...");
const response = await fetch(`https://api.pixlab.io/smartresize?img=${encodeURIComponent(img)}&key=${key}&width=${width}&height=${height}`);
const reply = await response.json();
if (reply.status !== 200) {
console.log(reply.error);
process.exit(1);
} else {
return reply.link; // Resized image
}
}
(async () => {
// First step, Detect & extract the landmarks for each human face present in the image.
let response = await fetch(`https://api.pixlab.io/facelandmarks?img=${encodeURIComponent(img)}&key=${key}`);
let reply = await response.json();
if (reply.status !== 200) {
console.log(reply.error);
process.exit(1);
}
const total = reply.faces.length; // Total detected faces
if (total < 1) {
console.log("No faces were detected..exiting");
process.exit(1);
}
console.log(`${total} faces were detected`);
// This list contain all the coordinates of the regions where the flower crown or the dog parts should be
// Composited on top of the target image later using the `merge` command.
let coordinates = [];
// Iterate all over the detected faces and make our stuff
for (let face of reply.faces) {
// Show the face coordinates
console.log("Coordinates...");
let cord = face.rectangle;
console.log(`\twidth: ${cord.width} height: ${cord.height} x: ${cord.left} y: ${cord.top}`);
// Show landmarks of interest:
console.log("Landmarks...");
let landmarks = face.landmarks;
console.log(`\tNose: X: ${landmarks.nose.x}, Y: ${landmarks.nose.y}`);
console.log(`\tBottom Lip: X: ${landmarks.bottom_lip.x}, Y: ${landmarks.bottom_lip.y}`);
console.log(`\tTop Lip: X: ${landmarks.top_lip.x}, Y: ${landmarks.top_lip.y}`);
console.log(`\tChin: X: ${landmarks.chin.x}, Y: ${landmarks.chin.y}`);
console.log(`\tMouth Left: X: ${landmarks.mouth_left.x}, Y: ${landmarks.mouth_left.y}`);
console.log(`\tMouth Right: X: ${landmarks.mouth_right.x}, Y: ${landmarks.mouth_right.y}`);
console.log(`\tBone Center: X: ${landmarks.bone.center.x}, Y: ${landmarks.bone.center.y}`);
console.log(`\tBone Outer Left: X: ${landmarks.bone.outer_left.x}, Y: ${landmarks.bone.outer_left.y}`);
console.log(`\tBone Outer Right: X: ${landmarks.bone.outer_right.x}, Y: ${landmarks.bone.outer_right.y}`);
console.log(`\tEye Pupil Left: X: ${landmarks.eye.pupil_left.x}, Y: ${landmarks.eye.pupil_left.y}`);
console.log(`\tEye Pupil Right: X: ${landmarks.eye.pupil_right.x}, Y: ${landmarks.eye.pupil_right.y}`);
console.log(`\tEye Left Brown Inner: X: ${landmarks.eye.left_brow_inner.x}, Y: ${landmarks.eye.left_brow_inner.y}`);
console.log(`\tEye Right Brown Inner: X: ${landmarks.eye.right_brow_inner.x}, Y: ${landmarks.eye.right_brow_inner.y}`);
console.log(`\tEye Left Outer: X: ${landmarks.eye.left_outer.x}, Y: ${landmarks.eye.left_outer.y}`);
console.log(`\tEye Right Outer: X: ${landmarks.eye.right_outer.x}, Y: ${landmarks.eye.right_outer.y}`);
draw_crown = !draw_crown;
if (draw_crown) {
// Resize the flower crown to fit the face width
let fit_crown = await smart_resize(
flower,
20 + cord.width, // Face width
0 // Let Pixlab decide the best height for this picture
);
// Composite the flower crown on top of the bone most left region.
console.log(`\tCrown flower at: X: ${landmarks.bone.outer_left.x}, Y: ${landmarks.bone.outer_left.y}`);
coordinates.push({
img: fit_crown, // The resized flower crown
x: landmarks.bone.outer_left.x,
y: landmarks.bone.outer_left.y
});
} else {
// Do the dog parts using the bone left & right regions and the nose coordinates.
console.log("\tDog Parts Regions...");
coordinates.push({
img: await smart_resize(dog_left_ear, cord.width/2, cord.height/2),
x: landmarks.bone.outer_left.x, // Adjust to get optimal effect
y: landmarks.bone.outer_left.y // Adjust to get optimal effect
});
coordinates.push({
img: await smart_resize(dog_right_ear, cord.width/2, cord.height/2),
x: landmarks.bone.outer_right.x, // Adjust to get optimal effect
y: landmarks.bone.outer_right.y // Adjust to get optimal effect
});
coordinates.push({
img: await smart_resize(dog_nose, cord.width/2, cord.height/2),
x: landmarks.nose.x - 18, // Adjust to get optimal effect
y: landmarks.nose.y - 10 // Adjust to get optimal effect
});
}
}
// Finally, Perform the composite operation when we exit the loop
console.log("Composite operation...");
response = await fetch('https://api.pixlab.io/merge', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
src: img, // The target image.
key: key,
cord: coordinates // The coordinates list filled earlier with the resized images (flower crown & dog members) and the regions of interest
})
});
reply = await response.json();
if (reply.status !== 200) {
console.log(reply.error);
} else {
// Optionally call blur, oilpaint, grayscale for cool background effects..
console.log("Snap Filter Effect: " + reply.link);
}
})();
<?php
// Mimic the two famous Snapchat filters: The flower crown & the dog parts filter.
// The target image must contain at least one human face. The more faces you got, the more funny it should be!
// Target image to composite stuff on. Must contain at least one face.
$img = 'https://trekkerscrapbook.files.wordpress.com/2013/09/face-08.jpg';
// The flower crown.
$flower = 'http://pixlab.xyz/images/flower_crown.png';
// The dog parts: Left & right ears, nose & optionally the tongue
$dog_left_ear = 'http://pixlab.xyz/images/dog_left_ear.png';
$dog_right_ear = 'http://pixlab.xyz/images/dog_right_ear.png';
$dog_nose = 'http://pixlab.xyz/images/dog_nose.png';
$dog_tongue = 'http://pixlab.xyz/images/dog_tongue.png';
// Your PixLab API key
$key = 'My_PIXLAB_API_KEY';
// If set to true then composite the flower crown. Otherwise, composite the dog stuff.
$draw_crown = false;
// Resize an image (Dog parts or the flower crown) to fit the face dimension using smartresize.
function smart_resize($img, $width, $height, $key) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/smartresize');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'img' => $img,
'key' => $key,
'width' => $width,
'height' => $height
]));
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
}
return $reply['link']; // Resized image
}
// First step, Detect & extract the landmarks for each human face present in the image.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/facelandmarks?'.http_build_query([
'img' => $img,
'key' => $key
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
}
$total = count($reply['faces']); // Total detected faces
if ($total < 1) {
die("No faces were detected..exiting");
}
echo $total . " faces were detected\n";
// This list contain all the coordinates of the regions where the flower crown or the dog parts should be
$coordinates = [];
// Iterate all over the detected faces and make our stuff
foreach ($reply['faces'] as $face) {
// Show the face coordinates
echo "Coordinates...\n";
$cord = $face['rectangle'];
echo "\twidth: " . $cord['width'] . " height: " . $cord['height'] . " x: " . $cord['left'] . " y: " . $cord['top'] . "\n";
// Show landmarks of interest:
echo "Landmarks...\n";
$landmarks = $face['landmarks'];
echo "\tNose: X: " . $landmarks['nose']['x'] . ", Y: " . $landmarks['nose']['y'] . "\n";
echo "\tBottom Lip: X: " . $landmarks['bottom_lip']['x'] . ", Y: " . $landmarks['bottom_lip']['y'] . "\n";
echo "\tTop Lip: X: " . $landmarks['top_lip']['x'] . ", Y: " . $landmarks['top_lip']['y'] . "\n";
echo "\tChin: X: " . $landmarks['chin']['x'] . ", Y: " . $landmarks['chin']['y'] . "\n";
echo "\tMouth Left: X: " . $landmarks['mouth_left']['x'] . ", Y: " . $landmarks['mouth_left']['y'] . "\n";
echo "\tMouth Right: X: " . $landmarks['mouth_right']['x'] . ", Y: " . $landmarks['mouth_right']['y'] . "\n";
echo "\tBone Center: X: " . $landmarks['bone']['center']['x'] . ", Y: " . $landmarks['bone']['center']['y'] . "\n";
echo "\tBone Outer Left: X: " . $landmarks['bone']['outer_left']['x'] . ", Y: " . $landmarks['bone']['outer_left']['y'] . "\n";
echo "\tBone Outer Right: X: " . $landmarks['bone']['outer_right']['x'] . ", Y: " . $landmarks['bone']['outer_right']['y'] . "\n";
echo "\tEye Pupil Left: X: " . $landmarks['eye']['pupil_left']['x'] . ", Y: " . $landmarks['eye']['pupil_left']['y'] . "\n";
echo "\tEye Pupil Right: X: " . $landmarks['eye']['pupil_right']['x'] . ", Y: " . $landmarks['eye']['pupil_right']['y'] . "\n";
echo "\tEye Left Brown Inner: X: " . $landmarks['eye']['left_brow_inner']['x'] . ", Y: " . $landmarks['eye']['left_brow_inner']['y'] . "\n";
echo "\tEye Right Brown Inner: X: " . $landmarks['eye']['right_brow_inner']['x'] . ", Y: " . $landmarks['eye']['right_brow_inner']['y'] . "\n";
echo "\tEye Left Outer: X: " . $landmarks['eye']['left_outer']['x'] . ", Y: " . $landmarks['eye']['left_outer']['y'] . "\n";
echo "\tEye Right Outer: X: " . $landmarks['eye']['right_outer']['x'] . ", Y: " . $landmarks['eye']['right_outer']['y'] . "\n";
$draw_crown = !$draw_crown;
if ($draw_crown) {
// Resize the flower crown to fit the face width
$fit_crown = smart_resize(
$flower,
20 + $cord['width'], // Face width
0, // Let Pixlab decide the best height
$key
);
// Composite the flower crown on top of the bone most left region.
echo "\tCrown flower at: X: " . $landmarks['bone']['outer_left']['x'] . ", Y: " . $landmarks['bone']['outer_left']['y'] . "\n";
$coordinates[] = [
'img' => $fit_crown,
'x' => $landmarks['bone']['outer_left']['x'],
'y' => $landmarks['bone']['outer_left']['y']
];
} else {
// Do the dog parts using the bone left & right regions and the nose coordinates.
echo "\tDog Parts Regions...\n";
$coordinates[] = [
'img' => smart_resize($dog_left_ear, $cord['width']/2, $cord['height']/2, $key),
'x' => $landmarks['bone']['outer_left']['x'],
'y' => $landmarks['bone']['outer_left']['y']
];
$coordinates[] = [
'img' => smart_resize($dog_right_ear, $cord['width']/2, $cord['height']/2, $key),
'x' => $landmarks['bone']['outer_right']['x'],
'y' => $landmarks['bone']['outer_right']['y']
];
$coordinates[] = [
'img' => smart_resize($dog_nose, $cord['width']/2, $cord['height']/2, $key),
'x' => $landmarks['nose']['x'] - 18,
'y' => $landmarks['nose']['y'] - 10
];
}
}
// Finally, Perform the composite operation
echo "Composite operation...\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/merge');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'src' => $img,
'key' => $key,
'cord' => $coordinates
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
} else {
echo "Snap Filter Effect: " . $reply['link'] . "\n";
}
require 'net/http'
require 'uri'
require 'json'
# Target image to composite stuff on. Must contain at least one face.
img = 'https://trekkerscrapbook.files.wordpress.com/2013/09/face-08.jpg'
# The flower crown.
flower = 'http://pixlab.xyz/images/flower_crown.png'
# The dog parts: Left & right ears, nose & optionally the tongue
dog_left_ear = 'http://pixlab.xyz/images/dog_left_ear.png'
dog_right_ear = 'http://pixlab.xyz/images/dog_right_ear.png'
dog_nose = 'http://pixlab.xyz/images/dog_nose.png'
dog_tongue = 'http://pixlab.xyz/images/dog_tongue.png'
# Your PixLab API key
key = 'My_PIXLAB_API_KEY'
# If set to True then composite the flower crown. Otherwise, composite the dog stuff.
draw_crown = false
# Resize an image (Dog parts or the flower crown) to fit the face dimension using smartresize.
def smart_resize(img, width, height)
puts "Resizing images..."
uri = URI.parse('https://api.pixlab.io/smartresize')
params = {
'img' => img,
'key' => key,
'width' => width,
'height' => height
}
uri.query = URI.encode_www_form(params)
req = Net::HTTP.get_response(uri)
reply = JSON.parse(req.body)
if reply['status'] != 200
puts reply['error']
exit
else
return reply['link'] # Resized image
end
end
# First step, Detect & extract the landmarks for each human face present in the image.
uri = URI.parse('https://api.pixlab.io/facelandmarks')
params = {
'img' => img,
'key' => key
}
uri.query = URI.encode_www_form(params)
req = Net::HTTP.get_response(uri)
reply = JSON.parse(req.body)
if reply['status'] != 200
puts reply['error']
exit
end
total = reply['faces'].length # Total detected faces
if total < 1
puts "No faces were detected..exiting"
exit
end
puts "#{total} faces were detected"
# This list contain all the coordinates of the regions where the flower crown or the dog parts should be
# Composited on top of the target image later using the `merge` command.
coordinates = []
# Iterate all over the detected faces and make our stuff
reply['faces'].each do |face|
# Show the face coordinates
puts "Coordinates..."
cord = face['rectangle']
puts "\twidth: #{cord['width']} height: #{cord['height']} x: #{cord['left']} y: #{cord['top']}"
# Show landmarks of interest:
puts "Landmarks..."
landmarks = face['landmarks']
puts "\tNose: X: #{landmarks['nose']['x']}, Y: #{landmarks['nose']['y']}"
puts "\tBottom Lip: X: #{landmarks['bottom_lip']['x']}, Y: #{landmarks['bottom_lip']['y']}"
puts "\tTop Lip: X: #{landmarks['top_lip']['x']}, Y: #{landmarks['top_lip']['y']}"
puts "\tChin: X: #{landmarks['chin']['x']}, Y: #{landmarks['chin']['y']}"
puts "\tMouth Left: X: #{landmarks['mouth_left']['x']}, Y: #{landmarks['mouth_left']['y']}"
puts "\tMouth Right: X: #{landmarks['mouth_right']['x']}, Y: #{landmarks['mouth_right']['y']}"
puts "\tBone Center: X: #{landmarks['bone']['center']['x']}, Y: #{landmarks['bone']['center']['y']}"
puts "\tBone Outer Left: X: #{landmarks['bone']['outer_left']['x']}, Y: #{landmarks['bone']['outer_left']['y']}"
puts "\tBone Outer Right: X: #{landmarks['bone']['outer_right']['x']}, Y: #{landmarks['bone']['outer_right']['y']}"
puts "\tBone Center: X: #{landmarks['bone']['center']['x']}, Y: #{landmarks['bone']['center']['y']}"
puts "\tEye Pupil Left: X: #{landmarks['eye']['pupil_left']['x']}, Y: #{landmarks['eye']['pupil_left']['y']}"
puts "\tEye Pupil Right: X: #{landmarks['eye']['pupil_right']['x']}, Y: #{landmarks['eye']['pupil_right']['y']}"
puts "\tEye Left Brown Inner: X: #{landmarks['eye']['left_brow_inner']['x']}, Y: #{landmarks['eye']['left_brow_inner']['y']}"
puts "\tEye Right Brown Inner: X: #{landmarks['eye']['right_brow_inner']['x']}, Y: #{landmarks['eye']['right_brow_inner']['y']}"
puts "\tEye Left Outer: X: #{landmarks['eye']['left_outer']['x']}, Y: #{landmarks['eye']['left_outer']['y']}"
puts "\tEye Right Outer: X: #{landmarks['eye']['right_outer']['x']}, Y: #{landmarks['eye']['right_outer']['y']}"
draw_crown = !draw_crown
if draw_crown
# Resize the flower crown to fit the face width
fit_crown = smart_resize(
flower,
20 + cord['width'], # Face width
0 # Let Pixlab decide the best height for this picture
)
# Composite the flower crown on top of the bone most left region.
puts "\tCrown flower at: X: #{landmarks['bone']['outer_left']['x']}, Y: #{landmarks['bone']['outer_left']['y']}"
coordinates << {
'img' => fit_crown, # The resized flower crown
'x' => landmarks['bone']['outer_left']['x'],
'y' => landmarks['bone']['outer_left']['y']
}
else
# Do the dog parts using the bone left & right regions and the nose coordinates.
puts "\tDog Parts Regions..."
coordinates << {
'img' => smart_resize(dog_left_ear, cord['width']/2, cord['height']/2),
'x' => landmarks['bone']['outer_left']['x'], # Adjust to get optimal effect
'y' => landmarks['bone']['outer_left']['y'] # Adjust to get optimal effect
}
coordinates << {
'img' => smart_resize(dog_right_ear, cord['width']/2, cord['height']/2),
'x' => landmarks['bone']['outer_right']['x'], # Adjust to get optimal effect
'y' => landmarks['bone']['outer_right']['y'] # Adjust to get optimal effect
}
coordinates << {
'img' => smart_resize(dog_nose, cord['width']/2, cord['height']/2),
'x' => landmarks['nose']['x'] - 18, # Adjust to get optimal effect
'y' => landmarks['nose']['y'] - 10 # Adjust to get optimal effect
}
end
end
# Finally, Perform the composite operation when we exit the loop
puts "Composite operation..."
uri = URI.parse('https://api.pixlab.io/merge')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
req.body = {
'src' => img, # The target image.
'key' => key,
'cord' => coordinates # The coordinates list filled earlier with the resized images (flower crown & dog members) and the regions of interest
}.to_json
res = http.request(req)
reply = JSON.parse(res.body)
if reply['status'] != 200
puts reply['error']
else
# Optionally call blur, oilpaint, grayscale for cool background effects..
puts "Snap Filter Effect: #{reply['link']}"
end
Similar API Endpoints
bg-remove, nsfw, sfw, ocr, crop, imgdiff, grayscale, drawrectangles, mogrify, meme, tagimg, faceverify ↗, facelookup ↗, screencapture, merge, smartresize, composite