PHP integration


Amend is a Platform–as-a-Service (PaaS) solution hosted on cloud. Amend helps you manage your application’s image resources in the cloud without having to worry about scale and performance. The resources are delivered by high-performance servers through Content Delivery Network (CDN).

Resources are uploaded, managed, and transformed using amend’s easy to use APIs and SDKs. Infrastructure used for these operations is infinitely scalable for handling high load and bursts of traffic.

Quick example

Take a look at the following Amend URL that generates the image below:

Image fit face with width 150 and height 150, radius 20, rotated to 20
150x150 PNG

By calling the above URL Amend is being instructed to transform the uploaded image and create a 150x150px thumbnail using face detection based cropping, round the image's corners, rotate the image by 20 degrees and then deliver resulting image through CDN.

PHP Library Features

Amend provides an open source PHP library for further simplifying the integration:

  • Build URLs for image transformation & manipulation.
  • PHP view helper methods for embedding and transforming images.
  • API wrappers: image upload.

The library was tested with PHP 5.5 and PHP 5.6.

PHP - Getting started guide

1. Installation

Amend's PHP integration library is available as an open-source PHP code. You can download the latest sources from the following link:

Copy all files from the src folder into your PHP project and include Amend's PHP classes in your code:

require 'Amend.php';

2. Configuration

Your amend_name account parameter is required to build image URLs. access_key and access_secret are further needed to perform secure API calls to Amend (e.g., image uploads). See API, URLs and access identifiers for more details.

Setting the configuration parameters can be done either programmatically in each call to a Amend method or globally using an environment variable or the config method.

You can find your configuration parameters in the dashboard of our Management Console.

Here's an example of setting configuration parameters globally in your PHP application:

    "amendName" => "your-amendName",
    "accessKey" => "your-accessKey",
    "accessSecret" => "your-accessSecret")

3. Upload images

You can upload images from your PHP server. Uploading is done over HTTP or HTTPS using a secure protocol based on the access_key and access_secret parameters you provide.

The following command uploads a local file to Amend:

$fileContents =  file_get_contents($_FILES['fileToUpload']['tmp_name']); 
$resp = Amend::upload($fileContents);

Each image uploaded to Amend is assigned a unique Image Name and is available for immediate delivery and transformation. The upload method returns an associative array with content similar to that shown in the following example:

    [ImageName] => baby
    [Width] => 450
    [Height] => 203
    [Size] => 2100
    [MimeType] => image/jpg
    [Resolution] => 300
    [CreatedDate]=> 2016-09-10T13:25:11Z
    [CDNUrl] =>
    [SecureCDNUrl] =>

4. Display and manipulate images

To add images to your PHP view use the Amend::load helper method. This method generates the full image resource URL based on the given parameters and internally uses image tag to add the image to your HTML code:

For example, displaying the uploaded image with the sample Image Name, while providing an alternate text:

<?php echo Amend::load('baby', array('transform'=>array('width'=>250,'height'=>168))); ?>
255x168 JPG

Consider a case where you wish to display a small thumbnail of the uploaded image. Simply add the transformation instructions to your call. For example, displaying the 'baby' image transformed to fill a 100x150 rectangle:

<?php echo Amend::load('baby', array('transform'=>array('width'=>250,'height'=>168,'fit'=>Amend.FIT_FILL))); ?>
100x150 JPG

This is equivalent to:

<img src=",h_150,fit_fill/baby" width="100" height="150" >

Using various parameters, you can perform tons of image transformations. The PHP library builds Amend URLs that you can embed in your web and mobile views for dynamically transforming your uploaded images in the cloud and delivering the results through a fast CDN..

You can easily resize images, perform face detection based cropping, apply effects, overlay text or watermarks.

For a full list of supported transformations and their usage, refer to Image transformations.

5. Sample projects

To find additional useful code samples and learn how to integrate Amend with your PHP applications, take a look at our Sample Projects.

Basic PHP sample: Uploading local images to Amend and generating various transformation URLs, fetch remote image and perform transformations.

6. What's next

Sign up for a free account and follow the steps mentioned above to try Amend. Finished all steps? That's just an example of what Amend can offer

Stay tuned for updates, tips and tutorials: Twitter, Facebook.