Upload via URL endpoint
curl --request POST \
--url https://images.abstractapi.com/v1/url/ \
--header 'Content-Type: application/json' \
--data '
{
"api_key": "<string>",
"url": "<string>",
"lossy": true,
"quality": 123,
"resize": {}
}
'import requests
url = "https://images.abstractapi.com/v1/url/"
payload = {
"api_key": "<string>",
"url": "<string>",
"lossy": True,
"quality": 123,
"resize": {}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({api_key: '<string>', url: '<string>', lossy: true, quality: 123, resize: {}})
};
fetch('https://images.abstractapi.com/v1/url/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://images.abstractapi.com/v1/url/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'api_key' => '<string>',
'url' => '<string>',
'lossy' => true,
'quality' => 123,
'resize' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://images.abstractapi.com/v1/url/"
payload := strings.NewReader("{\n \"api_key\": \"<string>\",\n \"url\": \"<string>\",\n \"lossy\": true,\n \"quality\": 123,\n \"resize\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://images.abstractapi.com/v1/url/")
.header("Content-Type", "application/json")
.body("{\n \"api_key\": \"<string>\",\n \"url\": \"<string>\",\n \"lossy\": true,\n \"quality\": 123,\n \"resize\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://images.abstractapi.com/v1/url/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_key\": \"<string>\",\n \"url\": \"<string>\",\n \"lossy\": true,\n \"quality\": 123,\n \"resize\": {}\n}"
response = http.request(request)
puts response.read_body{
"original_size": 205559,
"original_height": 430,
"original_width": 1142,
"final_size": 181512,
"bytes_saved": 24047,
"final_height": 430,
"final_width": 1142,
"url": "https://abstractapi-images.s3.amazonaws.com/e6c6ea1f8bfd46be9ed357b9ce4240ff_dog.jpg"
}
Upload via URL endpoint
Abstract’s Image Processing and Optimization API is a simple yet powerful REST API that is used to convert, compress, or optimization an image that is provided via a URL or via POST to the API itself.
POST
/
v1
/
url
/
Upload via URL endpoint
curl --request POST \
--url https://images.abstractapi.com/v1/url/ \
--header 'Content-Type: application/json' \
--data '
{
"api_key": "<string>",
"url": "<string>",
"lossy": true,
"quality": 123,
"resize": {}
}
'import requests
url = "https://images.abstractapi.com/v1/url/"
payload = {
"api_key": "<string>",
"url": "<string>",
"lossy": True,
"quality": 123,
"resize": {}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({api_key: '<string>', url: '<string>', lossy: true, quality: 123, resize: {}})
};
fetch('https://images.abstractapi.com/v1/url/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://images.abstractapi.com/v1/url/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'api_key' => '<string>',
'url' => '<string>',
'lossy' => true,
'quality' => 123,
'resize' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://images.abstractapi.com/v1/url/"
payload := strings.NewReader("{\n \"api_key\": \"<string>\",\n \"url\": \"<string>\",\n \"lossy\": true,\n \"quality\": 123,\n \"resize\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://images.abstractapi.com/v1/url/")
.header("Content-Type", "application/json")
.body("{\n \"api_key\": \"<string>\",\n \"url\": \"<string>\",\n \"lossy\": true,\n \"quality\": 123,\n \"resize\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://images.abstractapi.com/v1/url/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_key\": \"<string>\",\n \"url\": \"<string>\",\n \"lossy\": true,\n \"quality\": 123,\n \"resize\": {}\n}"
response = http.request(request)
puts response.read_body{
"original_size": 205559,
"original_height": 430,
"original_width": 1142,
"final_size": 181512,
"bytes_saved": 24047,
"final_height": 430,
"final_width": 1142,
"url": "https://abstractapi-images.s3.amazonaws.com/e6c6ea1f8bfd46be9ed357b9ce4240ff_dog.jpg"
}
Getting started
Base URL
https://images.abstractapi.com/v1/url
Validation endpoint
Along with your API key, the url endpoint required aurl parameter.
https://images.abstractapi.com/v1/url
--data '{
"api_key": "YOUR_UNIQUE_API_KEY",
"url": "https://s3.amazonaws.com/static.abstractapi.com/test-images/dog.jpg"
}'
{
"original_size": 205559,
"original_height": 430,
"original_width": 1142,
"final_size": 181512,
"bytes_saved": 24047,
"final_height": 430,
"final_width": 1142,
"url": "https://abstractapi-images.s3.amazonaws.com/e6c6ea1f8bfd46be9ed357b9ce4240ff_dog.jpg"
}
Request parameters
String
required
Your unique API key. Note that each user has unique API keys for each of Abstract’s APIs, so your Image API key will not work for your User Avatar API, for example.
String
required
The URL of the image that you would like to edit. Note that is cannot be more than 32 MB in size.
Boolean
If true, the API will perform a lossy compression on the image, reducing the size massively with a small drop in image quality. If false, the image size will only be reduced slightly (10% - 20% at most), but there will be no reduction in image quality. The default value is false if this is not provided.
Integer
This is an integer between 0 and 100 that determines the quality level for lossy compression. If not submitted it will be determined intelligently. Generally a quality above 95 is useless and may result in an image that is larger than the input image, and a quality below 25 will result in an image so low in quality that it will be useless.
Object
This is a set of JSON data that will determine how to resize the image. If not provided, we will only compress the image as desired. Find specific configurations for this parameter below.
Response parameters
The API response is returned in a universal and lightweight JSON format.Integer
The original size of the provided image, in bytes.
Integer
The original height of the provided image, in bytes.
Integer
The original width of the provided image, in bytes.
Integer
The final size of the processed image, in bytes.
Integer
The number of bytes saved by optimizing the image, in bytes.
Integer
The final height of the processed image, in bytes.
Integer
The final width of the processed image, in bytes.
String
The URL with the new processed image.
Options for “resize” parameter
The resize parameter takes a set of JSON data that determines how to resize the image. That JSON data can contain one or many of the following resizing strategies:exact : Resize to exact width and height. Aspect ratio will not be maintained
"resize": {
"width": 100,
"height": 75,
"strategy": "exact"
}
portrait : Exact height will be set, width will be adjusted according to aspect ratio
"resize": {
"height": 75,
"strategy": "portrait"
}
landscape : Exact width will be set, height will be adjusted according to aspect ratio
"resize": {
"width": 100,
"strategy": "landscape"
}
auto : The best strategy (portrait or landscape) will be selected according to its aspect ratio
"resize": {
"width": 100,
"height": 75,
"strategy": "auto"
}
fit : This option will crop and resize the image to fit the desired width and height.
"resize": {
"width": 100,
"height": 75,
"strategy": "fit"
}
crop : This option will crop an image to the exact size you specify. The resulting cropped image can optionally be scaled by inclusion of a scale, which accepts a number representing the percentage by which the image should be scaled.
"resize": {
"width": 100,
"height": 75,
"strategy": "crop",
"scale": 50,
"crop_mode": "c",
}
- n or t - North / Top
- nw or tl - North West / Top Left
- ne or tr - North East / Top Right
- w or l - West / Left
- c - Center - this is the default gravity or direction, and applied when the crop_mode parameter is left out, or an invalid value is passed.
- e or r - East / Right
- se or br - South East / Bottom Right
- sw or bl - South West / Bottom Left
- s or b - South / Bottom
Please note that the crop_mode parameter can be used with both the fit and the crop strategies.
square : This strategy will crop the image by its shorter dimension to make it a square, then resize it to the specified size.
"resize": {
"size": 100,
"strategy": "square"
}
fill : This strategy allows you to resize the image to fit the specified bounds while preserving the aspect ratio. The optional background property allows you to specify a color which will be used to fill the unused portions of the previously specified bounds.
"resize": {
"width": 100,
"height": 75,
"strategy": "fill",
"background": "rgb(91, 126, 156)&ququot;
}