2017 © Pedro Peláez
 

library mediaserver

Helpers for OBB Media Serving

image

oneblackbear/mediaserver

Helpers for OBB Media Serving

  • Tuesday, January 15, 2013
  • by oneblackbear
  • Repository
  • 3 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

One Black Bear Mediaserver

Delegate image serving and resizing to a more powerful server, whilst maintaining a single local copy., (*1)

Installation

Installation is via composer for example add this to your composer.json:, (*2)

"require": {
  "php": ">=5.4",
  "oneblackbear/mediaserver": "1.0.*"
}

USAGE

For simple out of the box usage you will need the following configuration items, (*3)

  • The server acting as a media server
  • A private security key (which will prevent abuse by unauthorised users)
  • A full url to an image you would like to serve.

Basic Example

Use the following code to get up and running., (*4)

<?php
use OBB\Mediaserver\Asset;

$server = [
  "server"=>     "example.co.uk",
  "server_key"=> "secretexample"
];

$options = [
  "width"=>  300,
  "height"=> 300
];

$asset = new Asset($server);
$url = $asset->url("http://path/to/image.jpg", $options);
// Example output:
// http://example.co.uk/4nB7OmYXS1Duobw_1bhp9QcJImw=/300x300/smart/http://path/to/image.jpg

Served image example

http://m1.obb.im/ViIPnXE3v-e8kJWaUYBpGmKIbGU=/600x500/smart/isuzu.co.uk/m/81e072/1200.jpg, (*5)

The full url component is made up of 5 main parts., (*6)

  • The media server, in the example case "http://m1.obb.im"
  • The security signature eg: ViIPnXE3v-e8kJWaUYBpGmKIbGU=
  • The requested width and height as passed into the options
  • The display mode, in this case the default mode is smart
  • The url of the original image

Additional Options

Smart cropping is the default, since it uses OpenCV to detect the primary but you can also override this to force a preferred crop., (*7)

Take this example image: http://isuzu.co.uk/m/7c67e8/860.jpg, (*8)

This is the default smart crop using the following:, (*9)

$img_settings = [
  "width"=>600,
  "height"=>500,
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

http://m1.obb.im/apLfSdsm7Y2ViSPdn6d7zekZ44g=/600x500/smart/isuzu.co.uk/m/7c67e8/860.jpg, (*10)

Center Crop

$img_settings = [
  "width" =>600,
  "height"=>500,
  "mode"  =>"center"
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

http://m1.obb.im/d647itICnSyd8PCXf4NlXdbsX_o=/600x500/center/isuzu.co.uk/m/7c67e8/860.jpg, (*11)

Left Crop

$img_settings = [
  "width" =>600,
  "height"=>500,
  "mode"  =>"left"
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

http://m1.obb.im/Zme6sT9kw4KpU-Y-7wq2RpErqTM=/600x500/left/isuzu.co.uk/m/7c67e8/860.jpg, (*12)

Right Crop

$img_settings = [
  "width" =>600,
  "height"=>500,
  "mode"  =>"right"
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

http://m1.obb.im/G6WHVA-0O8Y958TFb4uM06gGj2Y=/600x500/right/isuzu.co.uk/m/7c67e8/860.jpg, (*13)

Width & Height Generation

In it's simplest usage, just specify a desired width and height and an image will be served, cropped where necessary, to match the required dimensions., (*14)

Ratio dependent generation

Simply replace the pro-ratio dimension with a zero. For example:, (*15)

$img_settings = [
  "width"=>700,
  "height"=>0,
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

Results in this image: http://m1.obb.im/tKqROt8jn_Sp-Bvm81IZOzLzRlU=/700x0/right/isuzu.co.uk/m/7c67e8/860.jpg, (*16)

For the inverse:, (*17)

$img_settings = [
  "width"=>0,
  "height"=>400,
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

Gets this image: http://m1.obb.im/B6OnIQHxbuV_9zfNXva6Xvgsiqg=/0x400/right/isuzu.co.uk/m/7c67e8/860.jpg, (*18)

Original Size

Finally, you can specify both width and height as zero to receive the original size back. Note that since this is the default for width and height you can just do this:, (*19)

$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg");

That will give the following image: http://m1.obb.im/nuXfoLZ9umswOZvg7reqeg9lYTo=/0x0/smart/isuzu.co.uk/m/7c67e8/860.jpg, (*20)

Image Metadata

Docs coming Soon, (*21)

Filters

The following filters are available, documentation will be forthcoming as the modules are enabled., (*22)

The filter is passed into the url options as a string., (*23)

Brightness

Alters the image brightness, with syntax:, (*24)

brightness(%num)

PHP Code to generate:, (*25)

$img_settings = [
  "filters"=>"brightness(60)"
];
$url = $asset->url("isuzu.co.uk/m/7c67e8/860.jpg", $img_settings);

Watermarking

Watermark filter allows an image overlay to be applied to the original image. This can also be used to add standard overlays to images, such as coming soon, or new bursts overlaid on product photography., (*26)

The syntax for watermarks is as follows:, (*27)

The Versions

15/01 2013

dev-master

9999999-dev http://github.com/oneblackbear/mediaserver

Helpers for OBB Media Serving

  Sources   Download

MIT

The Requires

  • php >=5.4.0