Skip to content

Commit

Permalink
Merge pull request #380 from Art4/upgrade-to-glide-3
Browse files Browse the repository at this point in the history
Upgrade to intervention/image 3
  • Loading branch information
ADmad authored Jan 27, 2024
2 parents f5ea9f6 + cfddb6a commit 648d788
Show file tree
Hide file tree
Showing 54 changed files with 683 additions and 586 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request: ~
push:
branches:
- master
- upgrade-to-glide-3

jobs:
coding-style:
Expand All @@ -13,22 +13,22 @@ jobs:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.3'
extensions: gd, imagick
- name: php-cs-fixer
run: |
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.4/php-cs-fixer.phar -q
php php-cs-fixer.phar fix --dry-run --diff
composer update --no-interaction --no-ansi --no-progress
vendor/bin/php-cs-fixer fix --dry-run --diff
tests:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
php-version: ['8.1', '8.2', '8.3', '8.4']
prefer-lowest: ['']
include:
- php-version: '7.2'
- php-version: '8.1'
prefer-lowest: 'prefer-lowest'
steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build
vendor
docs/_site
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
.history
14 changes: 14 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in('src')
->in('tests')
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'phpdoc_annotation_without_dot' => false,
])
->setFinder($finder)
;
13 changes: 0 additions & 13 deletions .php_cs.dist

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
}
],
"require": {
"php": "^7.2|^8.0",
"intervention/image": "^2.7",
"php": "^8.1",
"intervention/image": "^3.2",
"league/flysystem": "^2.0|^3.0",
"psr/http-message": "^1.0|^2.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.5|^9.0",
"phpunit/php-token-stream": "^3.1|^4.0"
"phpunit/php-token-stream": "^3.1|^4.0",
"friendsofphp/php-cs-fixer": "^3.48"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 5 additions & 6 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace League\Glide\Api;

use Intervention\Image\ImageManager;
use InvalidArgumentException;
use League\Glide\Manipulators\ManipulatorInterface;

class Api implements ApiInterface
Expand All @@ -18,7 +17,7 @@ class Api implements ApiInterface
/**
* Collection of manipulators.
*
* @var array
* @var ManipulatorInterface[]
*/
protected $manipulators;

Expand Down Expand Up @@ -59,15 +58,15 @@ public function getImageManager()
/**
* Set the manipulators.
*
* @param array $manipulators Collection of manipulators.
* @param ManipulatorInterface[] $manipulators Collection of manipulators.
*
* @return void
*/
public function setManipulators(array $manipulators)
{
foreach ($manipulators as $manipulator) {
if (!($manipulator instanceof ManipulatorInterface)) {
throw new InvalidArgumentException('Not a valid manipulator.');
throw new \InvalidArgumentException('Not a valid manipulator.');
}
}

Expand All @@ -94,14 +93,14 @@ public function getManipulators()
*/
public function run($source, array $params)
{
$image = $this->imageManager->make($source);
$image = $this->imageManager->read($source);

foreach ($this->manipulators as $manipulator) {
$manipulator->setParams($params);

$image = $manipulator->run($image);
}

return $image->getEncoded();
return $image->encodeByMediaType()->toString();
}
}
4 changes: 1 addition & 3 deletions src/Filesystem/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace League\Glide\Filesystem;

use Exception;

class FileNotFoundException extends Exception
class FileNotFoundException extends \Exception
{
}
4 changes: 1 addition & 3 deletions src/Filesystem/FilesystemException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace League\Glide\Filesystem;

use Exception;

class FilesystemException extends Exception
class FilesystemException extends \Exception
{
}
20 changes: 13 additions & 7 deletions src/Manipulators/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace League\Glide\Manipulators;

use Intervention\Image\Image;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Origin;
use League\Glide\Manipulators\Helpers\Color;

/**
Expand All @@ -13,11 +14,11 @@ class Background extends BaseManipulator
/**
* Perform background image manipulation.
*
* @param Image $image The source image.
* @param ImageInterface $image The source image.
*
* @return Image The manipulated image.
* @return ImageInterface The manipulated image.
*/
public function run(Image $image)
public function run(ImageInterface $image): ImageInterface
{
if (is_null($this->bg)) {
return $image;
Expand All @@ -26,9 +27,14 @@ public function run(Image $image)
$color = (new Color($this->bg))->formatted();

if ($color) {
$new = $image->getDriver()->newImage($image->width(), $image->height(), $color);
$new->mime = $image->mime;
$image = $new->insert($image, 'top-left', 0, 0);
$new = $image->driver()->createImage($image->width(), $image->height())
->fill($color)
->place($image, 'top-left', 0, 0)
->setOrigin(
new Origin($image->origin()->mediaType())
);

$image = $new;
}

return $image;
Expand Down
6 changes: 3 additions & 3 deletions src/Manipulators/BaseManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\Glide\Manipulators;

use Intervention\Image\Image;
use Intervention\Image\Interfaces\ImageInterface;

abstract class BaseManipulator implements ManipulatorInterface
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public function __get($name)
/**
* Perform the image manipulation.
*
* @return Image The manipulated image.
* @return ImageInterface The manipulated image.
*/
abstract public function run(Image $image);
abstract public function run(ImageInterface $image): ImageInterface;
}
8 changes: 4 additions & 4 deletions src/Manipulators/Blur.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\Glide\Manipulators;

use Intervention\Image\Image;
use Intervention\Image\Interfaces\ImageInterface;

/**
* @property string $blur
Expand All @@ -12,11 +12,11 @@ class Blur extends BaseManipulator
/**
* Perform blur image manipulation.
*
* @param Image $image The source image.
* @param ImageInterface $image The source image.
*
* @return Image The manipulated image.
* @return ImageInterface The manipulated image.
*/
public function run(Image $image)
public function run(ImageInterface $image): ImageInterface
{
$blur = $this->getBlur();

Expand Down
Loading

0 comments on commit 648d788

Please sign in to comment.