Skip to content

Commit

Permalink
Filters list added
Browse files Browse the repository at this point in the history
  • Loading branch information
beeyev authored May 27, 2023
1 parent 574a166 commit 8978e36
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public function someMethod()
```php
use Beeyev\Thumbor\Thumbor;
use Beeyev\Thumbor\Manipulations\Resize;
use Beeyev\Thumbor\Manipulations\Filter;

public function someMethod()
{
$thumbor = new Thumbor('https://thumbor.findtheinvisiblecow.com/', 'secretKey555');
$thumbor->addFilter('strip_icc');
$thumbor->addFilter('blur', 1);
$thumbor->addFilter(Filter::STRIP_EXIF);
$thumbor->addFilter(Filter::BLUR, 1);
$thumbor->resizeOrFit(500, Resize::ORIG);
$thumbor->smartCrop();
$thumbor->imageUrl('http://seriouscat.com/serious_cat.jpg');
Expand Down
216 changes: 216 additions & 0 deletions src/Manipulations/Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php

declare(strict_types=1);

namespace Beeyev\Thumbor\Manipulations;

/**
* Fit.
*
* @see \Beeyev\Thumbor\Thumbor::addFilter()
*/
class Filter
{
/**
* Overrides `AUTO_PNG_TO_JPG` config variable.
*
* @see https://thumbor.readthedocs.io/en/latest/autojpg.html
*/
const AUTO_JPG = 'autojpg';

/**
* Sets the background layer to the specified color.
*
* @see https://thumbor.readthedocs.io/en/latest/background_color.html
*/
const BACKGROUND_COLOR = 'background_color';

/**
* Applies a gaussian blur to the image.
*
* @see https://thumbor.readthedocs.io/en/latest/blur.html
*/
const BLUR = 'blur';

/**
* Increases or decreases the image brightness.
*
* @see https://thumbor.readthedocs.io/en/latest/brightness.html
*/
const BRIGHTNESS = 'brightness';

/**
* Increases or decreases the image contrast.
*
* @see https://thumbor.readthedocs.io/en/latest/contrast.html
*/
const CONTRAST = 'contrast';

/**
* Filter runs a convolution matrix (or kernel) on the image
*
* @see https://thumbor.readthedocs.io/en/latest/convolution.html
*/
const CONVOLUTION = 'convolution';

/**
* Filter is used in GIFs to extract their first frame as the image to be used as cover.
*
* @see https://thumbor.readthedocs.io/en/latest/cover.html
*/
const COVER = 'cover';

/**
* Equalizes the color distribution in the image.
*
* @see https://thumbor.readthedocs.io/en/latest/equalize.html
*/
const EQUALIZE = 'equalize';

/**
* Extract focal points
*
* @see https://thumbor.readthedocs.io/en/latest/extract_focal_points.html
*/
const EXTRACT_FOCAL = 'extract_focal';

/**
* Returns an image sized exactly as requested independently of its ratio.
*
* @see https://thumbor.readthedocs.io/en/latest/filling.html
*/
const FILL = 'fill';

/**
* Adds a focal point, which is used in later transforms.
*
* @see https://thumbor.readthedocs.io/en/latest/focal.html
*/
const FOCAL = 'focal';

/**
* Specifies the output format of the image.
*
* @see https://thumbor.readthedocs.io/en/latest/format.html
*/
const FORMAT = 'format';

/**
* Changes the image to grayscale.
*
* @see https://thumbor.readthedocs.io/en/latest/grayscale.html
*/
const GRAYSCALE = 'grayscale';

/**
* Automatically degrades the quality of the image until the image is under the specified amount of bytes.
*
* @see https://thumbor.readthedocs.io/en/latest/max_bytes.html
*/
const MAX_BYTES = 'max_bytes';

/**
* Filter tells thumbor not to upscale your images.
*
* @see https://thumbor.readthedocs.io/en/latest/no_upscale.html
*/
const NO_UPSCALE = 'no_upscale';

/**
* Adds noise to the image.
*
* @see https://thumbor.readthedocs.io/en/latest/noise.html
*/
const NOISE = 'noise';

/**
* Applies the specified proportion to the image’s height and width when cropping.
*
* @see https://thumbor.readthedocs.io/en/latest/proportion.html
*/
const PROPORTION = 'proportion';

/**
* Filter changes the overall quality of the JPEG image (does nothing for PNGs or GIFs).
*
* @see https://thumbor.readthedocs.io/en/latest/quality.html
*/
const QUALITY = 'quality';

/**
* Red eye
*
* @see https://thumbor.readthedocs.io/en/latest/red_eye.html
*/
const RED_EYE = 'red_eye';

/**
* Filter changes the amount of color in each of the three channels.
*
* @see https://thumbor.readthedocs.io/en/latest/rgb.html
*/
const RGB = 'rgb';

/**
* Rotates the given image according to the angle value passed.
*
* @see https://thumbor.readthedocs.io/en/latest/rotate.html
*/
const ROTATE = 'rotate';

/**
* Adds rounded corners to the image using the specified color as background.
*
* @see https://thumbor.readthedocs.io/en/latest/round_corners.html
*/
const ROUND_CORNER = 'round_corner';

/**
* Increases or decreases the image saturation.
*
* @see https://thumbor.readthedocs.io/en/latest/saturation.html
*/
const SATURATION = 'saturation';

/**
* Enhances apparent sharpness of the image.
*
* @see https://thumbor.readthedocs.io/en/latest/sharpen.html
*/
const SHARPEN = 'sharpen';

/**
* Stretches the image until it fits the required width and height, instead of cropping the image.
*
* @see https://thumbor.readthedocs.io/en/latest/stretch.html
*/
const STRETCH = 'stretch';

/**
* Removes any Exif information in the resulting image.
*
* @see https://thumbor.readthedocs.io/en/latest/strip_exif.html
*/
const STRIP_EXIF = 'strip_exif';

/**
* Removes any ICC information in the resulting image.
*
* @see https://thumbor.readthedocs.io/en/latest/strip_icc.html
*/
const STRIP_ICC = 'strip_icc';

/**
* Filter tells thumbor to upscale your images.
*
* @see https://thumbor.readthedocs.io/en/latest/upscale.html
*/
const UPSCALE = 'upscale';

/**
* Filter adds a watermark to the image.
*
* @see https://thumbor.readthedocs.io/en/latest/watermark.html
*/
const WATERMARK = 'watermark';
}
5 changes: 3 additions & 2 deletions src/Thumbor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Beeyev\Thumbor\Exceptions\ThumborException;
use Beeyev\Thumbor\Exceptions\ThumborInvalidArgumentException;
use Beeyev\Thumbor\Manipulations\Filter;
use Beeyev\Thumbor\Manipulations\Fit;
use Beeyev\Thumbor\Manipulations\Halign;
use Beeyev\Thumbor\Manipulations\Resize;
Expand Down Expand Up @@ -348,12 +349,12 @@ public function noSmartCrop(): self
/**
* Filters
*
* Add a filter, e.g. `->addFilter('round_corner', '20%7C20',0,0,0)->addFilter('cover')->addFilter('blur', 7)`.
* Add a filter, e.g. `->addFilter(Filter::ROUND_CORNER, '20%7C20',0,0,0)->addFilter('cover')->addFilter('blur', 7)`.
*
* @see https://thumbor.readthedocs.io/en/latest/usage.html#filters
* @see https://thumbor.readthedocs.io/en/latest/filters.html
*
* @param int|string|null ...$args
* @param Filter::*|int|string|null ...$args
*/
public function addFilter(string $filterName, ...$args): self
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Manipulations/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function testItChecksIfAddingFiltersIsWorkingCorrectly()
$thumbor = (new Thumbor())->imageUrl('abc.jpg')->addFilter('round_corner', '20%7C20', 0, 0, 0);
static::assertSame('unsafe/filters:round_corner(20%7C20,0,0,0)/abc.jpg', $thumbor->get());

$thumbor->addFilter('brightness', 5)->addFilter('blur', 7);
static::assertSame('unsafe/filters:round_corner(20%7C20,0,0,0):brightness(5):blur(7)/abc.jpg', $thumbor->get());
$thumbor->addFilter('brightness', 5)->addFilter('blur', 7)->addFilter('autojpg');
static::assertSame('unsafe/filters:round_corner(20%7C20,0,0,0):brightness(5):blur(7):autojpg()/abc.jpg', $thumbor->get());

$thumbor->noFilter();
static::assertSame('unsafe/abc.jpg', $thumbor->get());
Expand Down

0 comments on commit 8978e36

Please sign in to comment.