dev-master
9999999-dev http://github.com/oneblackbear/mediaserverHelpers for OBB Media Serving
MIT
The Requires
- php >=5.4.0
by Ross Riley
Wallogit.com
2017 © Pedro Peláez
Helpers for OBB Media Serving
Delegate image serving and resizing to a more powerful server, whilst maintaining a single local copy., (*1)
Installation is via composer for example add this to your composer.json:, (*2)
"require": {
"php": ">=5.4",
"oneblackbear/mediaserver": "1.0.*"
}
For simple out of the box usage you will need the following configuration items, (*3)
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
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)
ViIPnXE3v-e8kJWaUYBpGmKIbGU=
smart
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)
$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)
$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)
$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)
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)
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)
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)
Docs coming Soon, (*21)
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)
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);
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)
Helpers for OBB Media Serving
MIT