Php image acceleration and modification - Photon
JETPACK PHOTON WRAPPER
What is Photon?
Photon is an image acceleration and modification service for Jetpack-connected WordPress sites. Converted images are cached automatically and served from the WordPress.com CDN. Images can be cropped, resized, and filtered by using a simple API controlled by GET query arguments. When Photon is enabled in Jetpack, images are updated on the fly.
Why wrapper?
This wrapper allows you to use photon on your host (servers) and its fully object oriented.
Installation
$ composer require bencagri/photon
Notice: to use it on your servers, you need to install gmagick package
Sample implementation.
<?php
use Photon\Wrapper\Generate;
use Photon\Wrapper\Effect\Height;
use Photon\Wrapper\Effect\Width;
use Photon\Wrapper\Effects;
require 'vendor/autoload.php';
// Set your effects
$effects = new Effects(
new Width(500),
new Height(500)
);
$imageUrl = 'http://sample-site.com/sample-image.jpg';
//Generate image with your effects
$process = new Generate($imageUrl,$effects);
$process->process();
You can combine multiple effects also.
<?php
use Photon\Wrapper\Effect\Crop;
use Photon\Wrapper\Effect\Filter;
use Photon\Wrapper\Effects;
$crop = new Crop(500,250,330,300);
$effects = new Effects(
$crop,
new Filter('emboss')
);
Some Effects
Crop
Crop an image by percentages x-offset,y-offset,width,height (x,y,w,h).
Percentages are used so that you don’t need to recalculate the cropping when transforming the image in other ways such as resizing it.
Original image:
new Crop('250px','250px','700px','600px');
250px,250px,700px,700px takes a 700px by 700px rectangle from the source image starting at 250px offset from the left and 250px offset from the top.
After:
new Crop('160px','25','1400px','60');
shows you can also mix the parameters types, for example a 1400 pixels by 60% rectangle from the image starting at 160 pixels by 25%.
Image Source
https://www.pexels.com/photo/branches-daylight-environment-flowers-355296/
LetterBox
Add black letterboxing effect to images, by scaling them to width, height while maintaining the aspect ratio and filling the rest with black.
new LetterBox(700,600);
Original image:
After:
Image Source
https://www.pexels.com/photo/beach-beautiful-bridge-carribean-449627/
UnLetterBox
Remove black letterboxing effect from images with ulb. This function takes only one argument, true.
new UnLetterBox(true);
Filter
The filter parameter is optional and is used to apply one of multiple filters.
Valid values are: negate, grayscale, sepia, edgedetect, emboss, blurgaussian, blurselective, meanremoval.
new Filter($filterName);
Image Source
https://www.pexels.com/photo/beautifully-served-table-for-dinner-6269/
Colorize
Add color hues to an image with colorizeby passing a comma separated list of red,green,blue (RGB) values such as 255,0,0 (red), 0,255,0 (green), 0,0,255 (blue).
new Colorize(0,0,100);
Image Source
https://www.pexels.com/photo/bird-animal-white-pigeon-75973/
Check full documentation of all effects.
Contribute
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
Licence
- The Photon Wrapper is open-sourced software licensed under the MIT license.
- The Photon is open-sourced software licenced under GNU GENERaL PUBLIC LICENCE
Posted on Utopian.io - Rewarding Open Source Contributors
Leave Php image acceleration and modification - Photon to:
Read more #utopian-io posts
Best Posts From bencagri
We have not curated any of bencagri's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From bencagri
- Python Frameworks Comparison
- DNGO Assistant - Introducing Kali
- Book Cover Creator for DNGO
- Cem Karaca - Lets Go!
- Aurora - An Article Project with Symfony 4 and Domain Driven Design
- Trip Fairground - Turkish Psych Rock
- Is this a bug?
- SteemConnect provider for HybridAuth
- PhotonBundle for Symfony
- Php image acceleration and modification - Photon
- deprecated
- Did you ever need to use txt files as Database with Php?
- So, you did discover dmania.
- the last shoulder touch
- Free and extendable trading bot application for crypto currencies.
- Integration of Poloniex
- missing ticker/price endpoint