6px/6px

dev-master 2015-06-07 22:45 UTC

README

Build Status

PHP library for interacting with the 6px API. This library includes methods that makes sending image processing jobs to 6px easier.

Getting Started

Using composer we would need to add this to our composer.json file in the project:

{
    "require": {
        "6px/6px": "dev-master"
    }
}

Now we install:

# Install composer
curl -s http://getcomposer.org/installer | php
# Upgrade your install
php composer.phar install

Now we can autoload 6px:

<?php
require 'vendor/autoload.php';

Examples

If you want to simply upload an image to the 6px CDN:

use 6px\API;

/**
 * Set our API credentials and load our images
 *
 * It can be a path to a file on your machine.
 * It can be a file in the $_FILES array
 * It can be a location on the internet.
 */
$6px = API::init('***USER_ID***', '***API_KEY***', '***API_SECRET***')
    ->load('taxi', 'https://s3.amazonaws.com/ooomf-com-files/mtNrf7oxS4uSxTzMBWfQ_DSC_0043.jpg'); // Load in the main image

$output = $6px->output(array('taxi' => 'unsplashed_taxi'));

$output->tag('raw')->url('6px');

$6px->save(function($res) {
    var_dump($res);
});

Given that vintage photos are kind of kind of popular right now, let's take this up a notch:

use 6px\API;

$6px = API::init('***USER_ID***', '***API_KEY***', '***API_SECRET***')
    ->load('taxi', 'https://s3.amazonaws.com/ooomf-com-files/mtNrf7oxS4uSxTzMBWfQ_DSC_0043.jpg'); // Load in the main image

$output = $6px->output(array('taxi' => 'unsplashed_taxi'));

$output
    ->tag('vintage')
    ->url('6px')
    ->filter(array( 'sepia' => 70 ));

$6px->save(function($res) {
    var_dump($res);
});

So, we have a bit of an extreme sepia effect going on here, but that's fine. I think this deserves to be more of a thumbnail. We are going to resize it now:

use 6px\API;

$6px = API::init('***USER_ID***', '***API_KEY***', '***API_SECRET***')
    ->load('taxi', 'https://s3.amazonaws.com/ooomf-com-files/mtNrf7oxS4uSxTzMBWfQ_DSC_0043.jpg'); // Load in the main image

$output = $6px->output(array('taxi' => 'unsplashed_taxi'));

$output
    ->tag('vintage_thumb')
    ->url('6px')
    ->filter(array( 'sepia' => 70 ))
    ->resize(array( 'width' => 75 ));

$6px->save(function($res) {
    var_dump($res);
});

Another thing we can do is change the dominate color of an image:

use 6px\API;

$6px = API::init('***USER_ID***', '***API_KEY***', '***API_SECRET***')
    ->load('taxi', 'https://s3.amazonaws.com/ooomf-com-files/mtNrf7oxS4uSxTzMBWfQ_DSC_0043.jpg'); // Load in the main image

$output = $6px->output(array('taxi' => 'unsplashed_taxi'));

$output
    ->tag('green')
    ->url('6px')
    ->filter(array( 'colorize' => array( 'hex' => '#00FF00', 'strength' => 80 )));

$6px->save(function($res) {
    var_dump($res);
});

Let's blur the image at the same time.

use 6px\API;

$6px = API::init('***USER_ID***', '***API_KEY***', '***API_SECRET***')
    ->load('taxi', 'https://s3.amazonaws.com/ooomf-com-files/mtNrf7oxS4uSxTzMBWfQ_DSC_0043.jpg'); // Load in the main image

$output = $6px->output(array('taxi' => 'unsplashed_taxi'));

$output
    ->tag('green')
    ->url('6px')
    ->filter(array(
        'colorize' => array( 'hex' => '#00FF00', 'strength' => 80 ),
        'stackBlur' => 20
        ));

$6px->save(function($res) {
    var_dump($res);
});

Now that we have covered some of the simple use cases, feel free to refer to our documentation!

API Documentation

Keep us posted on the cool stuff you are doing by sending an email to support@6px.io. If you come across any issues or have suggestions please open an issue on GitHub.

Analytics