POST
/
v1
/
url
/
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": {}
}'
{
  "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 a url 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"
}'

This was a successful request and the API returns information about the image along with a link to download the new one.

Request parameters

api_key
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.

url
String
required

The URL of the image that you would like to edit. Note that is cannot be more than 32 MB in size.

lossy
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.

quality
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.

resize
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.

original_size
Integer

The original size of the provided image, in bytes.

original_height
Integer

The original height of the provided image, in bytes.

original_width
Integer

The original width of the provided image, in bytes.

final_size
Integer

The final size of the processed image, in bytes.

bytes_saved
Integer

The number of bytes saved by optimizing the image, in bytes.

final_height
Integer

The final height of the processed image, in bytes.

final_width
Integer

The final width of the processed image, in bytes.

url
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",  
}

If you want to crop from a direction other than the default “center”, you can specify a crop_mode parameter, which can take one of the following gravity (or direction) values:

  • 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

If you would like to crop a custom area from an image, you can do so by specifying the rectangular region you wish to extract as x, y, width and height. Optionally, you can pass a scale parameter (as mentioned above), which must be a number representing the percentage by which you would like to scale the image.

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;  
}

The background property can be formatted in HEX notation #f60 or #ff6600 or RGB rgb(255, 0, 0). The default background color is white.