pixelbin / pixelbin
Pixelbin Backend SDK for PHP helps you integrate the core Pixelbin features with your application.
v0.0.3
2024-02-21 09:35 UTC
Requires
- guzzlehttp/guzzle: ^7.7
- justinrainbow/json-schema: ^5.2
Requires (Dev)
- dms/phpunit-arraysubset-asserts: ^0.5.0
- phpunit/phpunit: ^10.3
README
Pixelbin Backend SDK for PHP helps you integrate the core Pixelbin features with your application.
Getting Started
Getting started with Pixelbin Backend SDK for PHP
Installation
composer require pixelbin/pixelbin
Usage
Quick Example
<?php require_once(__DIR__ . "/vendor/autoload.php"); use Pixelbin\Platform\PixelbinClient; use Pixelbin\Platform\PixelbinConfig; // Create client with your API_TOKEN $config = new PixelbinConfig([ "domain" => "https://api.pixelbin.io", "apiSecret" => "API_TOKEN", ]); // Create a pixelbin instance $pixelbin = new PixelbinClient($config); // Sync method call try { $result = $pixelbin->assets->listFiles(); #use result print_r($result); } catch (Exception $e) { print_r($e->getMessage()); } // Async method call try { $result = $pixelbin->assets->listFilesAsync(); // use result print_r($result); } catch (Exception $e) { print_r($e->getMessage()); }
Utilities
Pixelbin provides url utilities to construct and deconstruct Pixelbin urls.
url_to_obj
Deconstruct a pixelbin url
parameter | description | example |
---|---|---|
pixelbinUrl (string) | A valid pixelbin url | https://cdn.pixelbin.io/v2/your-cloud-name/z-slug/t.resize(h:100,w:200)~t.flip()/path/to/image.jpeg |
Returns:
property | description | example |
---|---|---|
cloudName (string) | The cloudname extracted from the url | your-cloud-name |
zone (string) | 6 character zone slug | z-slug |
version (string) | cdn api version | v2 |
options (object) | optional query parameters | |
transformations (array) | Extracted transformations from the url | |
filePath | Path to the file on Pixelbin storage | /path/to/image.jpeg |
baseUrl (string) | Base url | https://cdn.pixelbin.io/ |
Example:
<?php use Pixelbin\Utils\Url; $pixelbinUrl = "https://cdn.pixelbin.io/v2/your-cloud-name/z-slug/t.resize(h:100,w:200)~t.flip()/path/to/image.jpeg?dpr=2.0&f_auto=True" $obj = Url::url_to_obj($pixelbinUrl); $obj = url_to_obj(pixelbinUrl) // obj // { // "cloudName": "your-cloud-name", // "zone": "z-slug", // "version": "v2", // "options": { // "dpr": 2.0, // "f_auto": True, // }, // "transformations": [ // { // "plugin": "t", // "name": "resize", // "values": [ // { // "key": "h", // "value": "100" // }, // { // "key": "w", // "value": "200" // } // ] // }, // { // "plugin": "t", // "name": "flip", // } // ], // "filePath": "path/to/image.jpeg", // "baseUrl": "https://cdn.pixelbin.io" // }
obj_to_url
Converts the extracted url obj to a Pixelbin url.
property | description | example |
---|---|---|
cloudName (string) | The cloudname extracted from the url | your-cloud-name |
zone (string) | 6 character zone slug | z-slug |
version (string) | cdn api version | v2 |
options (object) | optional query parameters | |
transformations (array) | Extracted transformations from the url | |
filePath | Path to the file on Pixelbin storage | /path/to/image.jpeg |
baseUrl (string) | Base url | https://cdn.pixelbin.io/ |
<?php use Pixelbin\Utils\Url; $obj = [ "cloudName" => "your-cloud-name", "zone" => "z-slug", "version" => "v2", "options" => [ "dpr" => 2.0, "f_auto" => true, ], "transformations" => [ [ plugin: "t", name: "resize", values: [ [ "key" => "h", "value" => "100", ], [ "key" => "w", "value" => "200", ], ], ], [ "plugin" => "t", "name" => "flip", ], ], "filePath" => "path/to/image.jpeg", "baseUrl" => "https://cdn.pixelbin.io", ]; $url = Url::obj_to_url($obj); // $obj is as shown above // url // https://cdn.pixelbin.io/v2/your-cloud-name/z-slug/t.resize(h:100,w:200)~t.flip()/path/to/image.jpeg?dpr=2.0&f_auto=True