2017 © Pedro Peláez
 

library php-sdk

Helper classes used to interact with the Zara 4 API.

image

zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  • Saturday, December 9, 2017
  • by CBS Industries
  • Repository
  • 1 Watchers
  • 1 Stars
  • 932 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 0 % Grown

The README.md

Zara 4 PHP SDK

PHP SDK for the Zara 4 Image Compression API. For more information see Zara 4 API documentation, (*1)

Installation

Composer

You can install the SDK via Composer. Run the following command:, (*2)

composer require zara-4/php-sdk

To use the SDK, use Composer's autoload:, (*3)

require_once('vendor/autoload.php');

Authentication

All authentication with the Zara 4 API is handled by the PHP SDK. You simply need to provide your API_CLIENT_ID and API_CLIENT_SECRET when creating an API Client., (*4)

The Zara 4 API uses OAuth authentication, using access tokens to grant access. Access tokens are automatically generated and transparently refreshed by the PHP SDK., (*5)

Example API client setup, (*6)

use Zara4\API\Client;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);

To get your API credentials click here, (*7)

Image Processing

The Zara 4 PHP SDK offers extensive support for image processing, making integrating Zara 4 into your PHP application very simple., (*8)

All authentication and communication with the Zara 4 API is automatically handled, meaning you can compress both remote and local images in just 4 lines of code., (*9)

Local 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., (*10)

Example usage, (*11)

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");

Remote Image

To process images from a remote location (such as a website url), you should use a RemoteImageRequest. This downloads the image from the remote location to Zara 4 for processing. The image url given must be publicly accessible., (*12)

Example usage, (*13)

use Zara4\API\Client;
use Zara4\API\ImageProcessing\RemoteImageRequest;
use Zara4\API\ImageProcessing\ProcessedImage;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$originalImage = new RemoteImageRequest("https://example.com/original-image.jpg");
$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Cloud Image

To process images from a cloud location (such as a Google Drive or Dropbox), you should use a CloudImageRequest. This downloads the image from the cloud location to Zara 4 for processing., (*14)

Example usage, (*15)

use Zara4\API\Client;
use Zara4\API\ImageProcessing\CloudImageRequest;
use Zara4\API\ImageProcessing\ProcessedImage;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$cloudDriveId = '905aaac0-06bb-11e7-83da-0b30de6ae4a2'; // Replace with your cloud drive id
$cloudFileId  = '0B_x2cioi5h8IX1NwYkNDcE96Tlk'; // Replace with the id of the file you wish to compress
$originalImage = new CloudImageRequest($cloudDriveId, $cloudFileId);
$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Options

You can customise how your images are processed with Zara 4 by altering your request options., (*16)

Example usage, (*17)

use Zara4\API\Client;
use Zara4\API\ImageProcessing\LocalImageRequest;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$originalImage = new LocalImageRequest("/path/to/original-image.jpg");

// Change request options
$originalImage->optimisationMode = OptimisationMode::HIGHEST;
$originalImage->outputFormat = OutputFormat::MATCH;
$originalImage->colourEnhancement = ColourEnhancement::IMPROVE_COLOUR;
$originalImage->resizeMode = ResizeMode::NONE;

$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Uploading Compressed Images To Cloud Storage

As well as downloading compressed images, you can also request from them to be uploaded to one of your Cloud Storage locations., (*18)

$request = new \Zara4\API\ImageProcessing\LocalImageRequest('test-images/001.jpg');

// --- --- --- ---

// The id of the cloud storage drive to upload to (Replace with your cloud drive id)
// You can manage your Cloud Storage from https://zara4.com/account/cloud-storage
$destinationDriveId = '905aaac0-06bb-11e7-83da-0b30de6ae4a2';

// The name the uploaded file should be given on you Cloud Storage
$destinationFileName = 'YOUR FILE NAME';

// You can also specify the folder the compressed image should be uploaded to
// If you do not wish to specify a parent folder, set $destinationParentId = null
$destinationParentId = 'xxxxxxxxxxxxxxxxxxx';

$request->uploadToCloud($destinationDriveId, $destinationFileName, $destinationParentId);

// --- --- --- ---

$response = $this->client->processImage($request);

The Versions

09/12 2017

dev-master

9999999-dev https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

09/12 2017

v1.2.3.3

1.2.3.3 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

13/11 2017

v1.2.3.2

1.2.3.2 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

13/11 2017

v1.2.3.1

1.2.3.1 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

13/11 2017

v1.2.3

1.2.3.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

21/05 2017

v1.2.2

1.2.2.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

26/04 2017

v1.2.1.2

1.2.1.2 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

26/04 2017

v1.2.1.1

1.2.1.1 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

25/04 2017

v1.2.1

1.2.1.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

22/04 2017

v1.2.0

1.2.0.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

26/12 2016

v1.1.4

1.1.4.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

30/06 2016

v1.1.3

1.1.3.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

24/05 2016

v1.1.2

1.1.2.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

01/04 2016

v1.1.1

1.1.1.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

19/03 2016

v1.1.0

1.1.0.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

01/02 2016

v1.0.2

1.0.2.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

25/01 2016

v1.0.1

1.0.1.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation

14/01 2016

v1.0.0

1.0.0.0 https://github.com/zara-4/php-sdk

Helper classes used to interact with the Zara 4 API.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Colin Stannard

zara 4 image optimisation