curl https://images.abstractapi.com/v1/upload/ \
-X POST \
--form data='{api_key": "your-api-key", "lossy": true}' \
--form image=@path/to/image/file.jpg
{
"original_size": "the size of the original input image, in bytes",
"original_height": "original height in pixels of the image",
"original_width": "original width in pixels of the image",
"final_size": "the size of the new image, in bytes",
"bytes_saved": "the number of bytes saved by compressing and resizing the image",
"final_height": "final height in pixels of the image",
"final_width": "final width in pixels of the image",
"url": "url of the image hosted by abstract for you to download. Images are available for 1 day.",
}
PRO
$49
per
month
ENTERPRISE
$499
per
month
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.
The Image Processing and Optimization API, like all of Abstract's APIs, is organized around REST. It is designed to use predictable, resource-oriented URL's and to use HTTP status codes to indicate errors.
The Image Processing and Optimization API requires all communications to be secured TLS 1.2 or greater.
All of Abstract's API are versioned. The Image Processing and Optimization API is currently on Version 1.
Your API key is your unique authentication key to be used to access Abstract's Image Processing and Optimization API. Note that each of Abstract's APIs has a unique API key, so you will need different keys to access the Image Processing and Optimization and Website Screenshot APIs, for example. To authenticate your requests, you will need to append your API key to the base URL.
https://images.abstractapi.com/v1/
There are two methods to begin working with an image:
1. providing the API with a URL of the image
2. uploading the image directly to Abstract.
Providing the URL is simpler, as you just need to make a simple HTTP POST call with all of the necessary data in the payload as JSON.
To upload an existing image via URL, you will make an HTTP POST call to the following URL:
https://images.abstractapi.com/v1/url/
To use the API with a direct upload, you must make a multi-part HTTP POST (content type multipart/form-data). The base URL for this is https://images.abstractapi.com/v1/upload/
PARAMETER
TYPE
DETAILS
api_key required
String
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 as your User Avatar API key, for example.
url required
String
The URL of the image that you would like to edit. Note that is cannot be more than 32 MB in size.
To use the API with a direct upload, you must make a multi-part HTTP POST (content type multipart/form-data). The base URL for this is https://images.abstractapi.com/v1/upload/
The image should be uploaded as a file named "image", and the rest of the data should be json data uploaded with the name "data". The "data" argument should contain all the information from above EXCEPT the URL param which is not needed. Here's an example using curl:
curl https://images.abstractapi.com/v1/upload/ \
-X POST \
--form data='{api_key": "your-api-key", "lossy": true}' \
--form image=@path/to/image/file.jpg
Return data is in JSON format:
{
"original_size": "the size of the original input image, in bytes",
"original_height": "original height in pixels of the image",
"original_width": "original width in pixels of the image",
"final_size": "the size of the new image, in bytes",
"bytes_saved": "the number of bytes saved by compressing and resizing the image",
"final_height": "final height in pixels of the image",
"final_width": "final width in pixels of the image",
"url": "url of the image hosted by abstract for you to download. Images are available for 1 day.",
}
The Image Processing and Optimization API has 3 main functionalities, which can be used separately or independently as parameters on the request. These functionalities are:
PARAMETER
TYPE
DETAILS
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. Use only if you know what you are doing. 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
JSON
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.
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.
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
Please note that the crop_mode parameter can be used with both the fit and the crop strategies.
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.
"resize": {
"width": 100,
"height": 75,
"strategy": "crop",
"scale": 50,
"crop_mode": "c",
}
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. The background property can be formatted in HEX notation #f60 or #ff6600 or RGB rgb(255, 0, 0). The default background color is white.
"resize": {
"width": 100,
"height": 75,
"strategy": "fill",
"background": "rgb(91, 126, 156)"
}
Whenever you make a request that fails for some reason, an error is returned also in the JSON format. The errors include an error code and description, which you can find in detail below.
CODE
TYPE
DETAILS
200
OK
Everything worked as expected.
400
Bad request
Bad request
401
Unauthorized
The request was unacceptable. Typically due to the API key missing or incorrect.
500
Internal Server Error
The request could not be completed due to an error on the server side.
503
Service Unavailable
The server was unavailable.
An Image Processing & Optimization API provides a set of tools for a user to manipulate an image programatically. This can include but is not limited to reducing the image size, changing the image's dimensions, and more.
Image optimization has many technical, user experience, and economic benefits. First, programatic image processing such as through Abstract's API makes it easy for you to get images in a format that you require. Second, more optimized images are often smaller in size and load faster, and so result in a faster experience for users and overall a better user experience. And last, smaller images means less storage and lower costs. It's a win win win!
There are certainly trade offs to make between an image's size and its quality. The smaller an image is, the less quality it has, all things being equal. However, Abstract's Image Processing and Optimization API's are designed to reduce size without affecting quality too much. The trade offs between these two are also fully configurable in the API, so if you don't like the API's default settings, you can always change it.
May 31, 2023
-
Improved the algorithm to increase image optimization by 20%, providing higher quality output
November 18, 2020
-
Updated documentation with new crop strategies
July 8, 2020
-
Improved compression and optimization flows to improve quality and reduce speed
Each of our API's has a free plan as well as several paid options, which offer a greater number of requests, a higher level of data quality, and greater speed for higher prices. Please see the page above or sign into your account to view pricing for each API.
Absolutely! We want you to try before you buy. Each of our API's has a free tier with a generous usage allowance for you to try the product out and verify that the speed and data quality work for you.
We use Stripe to accept payment via major debit and credit cards (Visa, Mastercard, American Express). If you cannot use those payment methods, then contact us at team at abstractapi.com to arrange for an alternative payment method.
Yes, you can upgrade or downgrade your subscription at any time by visiting your dashboard. If you upgrade in the middle of a billing cycle, you will be charged a pro-rated amount for your new plan through the end of the billing cycle.
Yes, all of our subscriptions are month to month. You can cancel at any time, and you will not be charged again at the end of your billing cycle.
You can cancel your subscription at any time from your dashboard. Once canceled, your subscription will be active until the end your current billing cycle, and then it will be automatically moved to the free plan.
If your API usage exceeds the monthly limit set by your plan, then you will be charged a fee for each call over your limit. At the end of your billing period, your usage will reset again.
We do offer enterprise plans with custom features and pricing in limited circumstances. If our public pricing plans don't work for you, then contact us (team at abstractapi.com) and we'll work something out.
While we don't normally offer discounts, we do make exceptions for certain types of users and use cases. If you are a student or are engaged in academic work, or are working on a non-profit or open source project, we're happy to offer you discounts for our API's. Just email us at team at abstractapi.com.
All of our plans are currently paid month to month. We will be launching annual plans at a discount soon. If you're interested in an annual plan in the meantime, just contact us and we'll set you up.
We will typically attempt to charge your payment method up to three times after it fails. If we're still unable to collect payment, then your subscription will be automatically canceled and you'll be moved to the free plan.
Yes, a paid tier of our API may be used in conjunction with a commercial project. The free tiers of our API's may not be used in commercial projects.