NAV Open/Close menu
shell python php

Introduction

Welcome to Imagify API! You can use the API to optimize and resize your images.

API Libraries

A few libraries are already available to interact with our API. If you write your own library, we would be very happy to link you on this doc. Please contact us.

Python

You can directly install it with pip:

pip install imagify-python

You can also install it by cloning the Github Repo and doing a :

python setup.py install

PHP

You can direclty install it with composer:

composer install wp-media/imagify-php

You can also install it by cloning the Github Repo

Authentication

To authorize, use this code:

# With shell, you can just pass the correct header with each request
curl "https://app.imagify.io/api/endpoint/"
  -H "Authorization: token my_api_key"
from imagify import Imagify

imagify = Imagify('my_api_key')
<?php
require('class-imagify.php');

$imagify = new Imagify\Optimizer('my_api_key');

Make sure to replace my_api_key with your API key.

Imagify uses API keys to allow access to the API. You can register for free to get an API key at our website.

Imagify expects for the API key to be included in all API requests to the server in a header that looks like the following:

Authorization: token your_api_key

Upload

Upload and Optimize an image

<?php
require ('class-imagify.php');

$imagify = new Imagify\Optimizer('my_api_key');
$param = array(
    "level"=> 'ultra',
    "resize"=> array("width"=> 50),
    );
$image = '1.jpg';

$imagify->optimize($image, $param);
from imagify import Imagify

imagify = Imagify('my_api_key')

param = dict(ultra=True, resize=dict(width=50))
image = '1.jpg'

imagify.optimize(image, param)
curl "https://app.imagify.io/api/upload/"
  -H "Authorization: token my_api_key" -H "Content-Type: multipart/form-data" -F "[email protected]" -F 'data={"ultra":true, "resize":{"width":50}}'

The above command returns JSON structured like this:

  {
    "code": 200,
    "image": "http://storage.imagify.io/imagify/45dfi7h/1.jpg",
    "new_size": 100,
    "original_size": 200,
    "percent": 50,
    "success": true
  }

This endpoint allow you to upload and optimize an image.

HTTP Request

POST
https://app.imagify.io/api/upload/

Query Parameters

Query parameters should be send as a form-data request

Parameter Type Description
image binary data Your image file required
data json A json with optimization parameters

Data Parameters

By filling the data parameter you will be able to control the optimization and to resize images.

Parameter Type Default Description
normal bool false Optimization with a losseless algorithm
aggressive bool true Optimization with Agressive algorithm
ultra bool false Optimization with Ultra algorithm
keep_exif bool false Will allow you to preserve meta data in images
resize bool false Array with resize paramater
resize[“width”] int false Will resize the image with the given width
resize[“height”] int false Will resize the image with the given height
resize[“percentage”] int false Will resize the image with the given percentage

Subaccounts

You can create and manage sub-accounts, directly from our API

Create a sub-account

curl "https://app.imagify.io/api/subaccounts/"
  -H "Authorization: token my_api_key" -H "Content-Type: multipart/form-data" -F "first_name=foo&last_name=bar&[email protected]&quota=100&allow_over_quota=true&send_confirmation=false"

The above command returns JSON structured like this:

{"code":200,"id":599774,"success":true}

HTTP Request

POST
https://app.imagify.io/api/subaccounts/

Query Parameters

Query parameters should be send as a form-data request

Parameter Type Description
first_name text data The first name of the sub-account
last_name text The last name of the sub-account
email text The email associated to the sub-account required
quota float The quota in MB to give to the sub-account required
allow_over_quota bool If the sub-account can use more than his quota required
send_confirmation bool If true, an email will be send to the sub-account with the credentials required

Delete a sub-account

curl "https://app.imagify.io/api/subaccounts/{subaccount_id}/"
  -H "Authorization: token my_api_key" -X DELETE }"

The above command returns JSON structured like this:

{"success":true}

HTTP Request

DELETE
https://app.imagify.io/api/subaccounts/{subaccount_id}/

Errors

Imagify API uses the following error codes:

Error Code Meaning
400 Bad Request – Your request was not understandable
422 Already compressed – Your image is already compressed
403 Forbidden – You don’t have the proper right to access the data
404 Not Found – The specified ressource could not be found
405 Method Not Allowed – You tried to access an endpoint with an invalid method
415 Unsupported media type – The file you’ve uploaded is not supported
500 Internal Server Error – We had a problem with our server. Try again later.
503 Service Unavailable – We’re temporarially offline for maintanance. Please try again later.