Upload Image

To process images on your local machine you should use a LocalImageRequest.

This uploads the image from your machine to Zara 4 for processing.

Example usage

// Import Zara 4 classes
use Zara4\API\Client;
use Zara4\API\ImageProcessing\LocalImageRequest;
use Zara4\API\ImageProcessing\ProcessedImage;

// ...

$apiClient = new Client('API_CLIENT_ID', 'API_CLIENT_SECRET');
$originalImage = new LocalImageRequest("/path/to/original-image.jpg");
$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");
// Import Zara 4 classes
import com.zara4.api.*;

// ...

Client apiClient = new Client("API_CLIENT_ID", "API_CLIENT_SECRET");
LocalImageRequest originalImage = new LocalImageRequest("/path/to/original-image.jpg");
ProcessedImage processedImage = apiClient.processImage(originalImage);
apiClient.downloadProcessedImage(processedImage, "/where/to/save/compressed-image.jpg");
# Import Zara 4 classes
require 'zara4'

# ...

api_client = Zara4::API::Client.new({
  'client_id'     => 'API_CLIENT_ID',
  'client_secret' => 'API_CLIENT_SECRET'
})
original_image = Zara4::API::ImageProcessing::LocalImageRequest.new('/path/to/original-image.jpg')
processed_image = api_client.process_image(original_image)
api_client.download_processed_image(processed_image, '/where/to/save/compressed-image.jpg')
NODEJS CODE
PYTHON CODE
'Import Zara 4 classes'
Imports Zara4.API
Imports Zara4.API.ImageProcessing

'...'

Dim apiClient = new Client("API_CLIENT_ID", "API_CLIENT_SECRET")
Dim originalImage = New LocalImageRequest("/path/to/original-image.jpg")
Dim processedImage = apiClient.processImage(originalImage)
apiClient.downloadProcessedImage(processedImage, "/where/to/save/compressed-image.jpg")
// Import Zara 4 classes
using Zara4.API;
using Zara4.API.ImageProcessing;

// ...

Client apiClient = new Client("API_CLIENT_ID", "API_CLIENT_SECRET");
LocalImageRequest originalImage = new LocalImageRequest("/path/to/original-image.jpg");
ProcessedImage processedImage = apiClient.processImage(originalImage);
apiClient.downloadProcessedImage(processedImage, "/where/to/save/compressed-image.jpg");

Manual Request

To access the API you will need to provide an access_token (see authentication). You can also perform a limited number of image processing requests anonymously (without an access_token).

Upload Image Request

curl "https://api.zara4.com/v1/image-processing/request" \
  -F "access_token=ACCESS_TOKEN" \
  -F "file=@/path/to/your/image.jpg"

Example Response

{
  "status":"ok",
  "request-id":"6de1c660-b347-11e5-8c6e-b9b63cf255a8",
  "request":{
    "optimisation-mode":"compromise",
    "colour-enhancement":"none",
    "resize-mode":"none",
    "width":null,
    "height":null
  },
  "compression":{
    "bytes-original":2078890,
    "bytes-compressed":530036,
    "bytes-saving":1548854,
    "ratio-compression":0.2549610609508,
    "percentage-saving":74.50389390492
  },
  "generated-images":{
    "names":[
      "6de1c660-b347-11e5-8c6e-b9b63cf255a8.jpg"
    ],
    "urls":[
      "https:\/\/api.zara4.com\/v1\/file\/6de1c660-b347-11e5-8c6e-b9b63cf255a8\/6de1c660-b347-11e5-8c6e-b9b63cf255a8.jpg"
    ]
  }
}

Fetch compressed image

The response includes generated-images containing a list of urls for your optimised image.

Each url is valid for up to 2 hours. If you used an access_token to submit your image processing request, you will also need to use an access token to fetch an optimised image.

wget "https://api.zara4.com/v1/file/6de1c660-b347-11e5-8c6e-b9b63cf255a8/6de1c660-b347-11e5-8c6e-b9b63cf255a8.jpg?access_token=ACCESS_TOKEN"