Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to intervention/image 3 #380

Merged
merged 66 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
31d421c
define missing properties in tests
Art4 Jan 22, 2024
bf55901
bump php requiremet to 8.1
Art4 Jan 22, 2024
47fa747
update to intervention/glide v3
Art4 Jan 22, 2024
3105fa6
Update ServerFactory
Art4 Jan 22, 2024
be8e752
drop php <8.1 in github actions, add php 8.4
Art4 Jan 22, 2024
5ffd4f8
Fix test for Watermark
Art4 Jan 22, 2024
4b26c21
Activate github actions on dev branch
Art4 Jan 22, 2024
ab510fd
Upgrade to PHP-CS-Fixer 3
Art4 Jan 22, 2024
dfe5153
Install php-cs-fixer in github actions
Art4 Jan 22, 2024
d876753
Use new ImageInterface in Size Manipulator
Art4 Jan 22, 2024
50472ff
Fix tests in Sharpen manipulator
Art4 Jan 22, 2024
4a221bc
Fix tests for Pixelate manipulator
Art4 Jan 22, 2024
b7b9c59
Fix tests for Orientation manipulator
Art4 Jan 22, 2024
154ebea
Fix tests for Gamma manipulator
Art4 Jan 22, 2024
8397221
Fix tests for Flip manipulator
Art4 Jan 22, 2024
a1e3200
Fix tests for Filter manipulator
Art4 Jan 22, 2024
a8ae0ae
Update tests for Encode manipulator
Art4 Jan 22, 2024
43ba3cd
Update tests for Crop manipulator
Art4 Jan 22, 2024
8b5239b
Update tests for Contrast manipulator
Art4 Jan 22, 2024
7f87164
Update tests for Brightness manipulator
Art4 Jan 22, 2024
88f1324
Update tests for Border manipulator
Art4 Jan 22, 2024
87e4214
Update tests for Blur manipulator
Art4 Jan 22, 2024
7122694
fix tests for Background manipulator
Art4 Jan 22, 2024
c25ef4d
fix tests for Dimension helper
Art4 Jan 22, 2024
ca4f4cf
Fix tests in ApiTest
Art4 Jan 22, 2024
865cc26
Fix Background manipulator
Art4 Jan 24, 2024
69e4151
Fix watermark manipulator
Art4 Jan 24, 2024
44413aa
Fix size manipulator
Art4 Jan 24, 2024
56504cc
Fix tests in size manipulator
Art4 Jan 24, 2024
59eba7d
fix Orientation manipulator
konnng-dev Jan 24, 2024
aeb6010
Fix Api tests
Art4 Jan 24, 2024
9dd37f3
Fix code style with php-cs-fixer
Art4 Jan 24, 2024
0ed379c
fix Encode manipulator
konnng-dev Jan 24, 2024
c4e647d
Merge branch 'Art4-glide/upgrade-to-glide-3' into upgrade-to-glide-3
konnng-dev Jan 24, 2024
a786e51
Move Encoding into Api::run(), remove orientate(), interlace(), Encod…
Art4 Jan 24, 2024
e3b3dc1
fix Encoder modifier to detect file format properly
konnng-dev Jan 24, 2024
510ec64
fix Encoder Modifier tests
konnng-dev Jan 24, 2024
907b1bc
improve Orientation Modifier
konnng-dev Jan 24, 2024
7fe32ee
fix Orientation Modifier tests
konnng-dev Jan 24, 2024
14bdf5d
fixed code formatting
konnng-dev Jan 24, 2024
3d01591
fix Server Tests
konnng-dev Jan 24, 2024
9bc8881
.gitignore updated
konnng-dev Jan 24, 2024
2957c80
Fix Background Modifier
konnng-dev Jan 24, 2024
f51a627
fix Background Modifier
konnng-dev Jan 24, 2024
6a96ab7
fix Background Modifier Test
konnng-dev Jan 24, 2024
35170bd
Fix border manipulator
Art4 Jan 25, 2024
f5f3476
Fix usage of flip() and flop() in Flip manipulator
Art4 Jan 25, 2024
13ac3da
fix type casting errors
Art4 Jan 25, 2024
8000a81
Fix opacity of Watermark manipulator
Art4 Jan 25, 2024
155587c
Fix return type of watermark
Art4 Jan 25, 2024
eb917be
Fix code style
Art4 Jan 25, 2024
a819414
Merge remote-tracking branch 'konnng/upgrade-to-glide-3' into upgrade…
Art4 Jan 25, 2024
810cdc8
Fix flip and flop
Art4 Jan 25, 2024
a3fd090
Fix code style
Art4 Jan 25, 2024
9d10e69
Fix ApiTest
Art4 Jan 25, 2024
66ad315
Fix Border and Flip test
Art4 Jan 25, 2024
81144ef
Require at least intervention/image v3.2
Art4 Jan 25, 2024
6bc9dec
Fix border test.
ADmad Jan 25, 2024
fadf2d3
Fix size=contain
Art4 Jan 26, 2024
8078854
Fix size=max
Art4 Jan 26, 2024
4b0a0de
Fix "fill-max" resize
ADmad Jan 26, 2024
9e28ec5
Simplify "fill" and "fill-max" resizing.
ADmad Jan 26, 2024
1aea4e6
Fix crop fit
ADmad Jan 26, 2024
b3bde5d
Fix argument type
ADmad Jan 26, 2024
2c27102
Round the values before casting to int
ADmad Jan 26, 2024
cfddb6a
Uncommend Encode manipulator
Art4 Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build
vendor
docs/_site
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
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",
"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
43 changes: 37 additions & 6 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace League\Glide\Api;

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

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

Expand Down Expand Up @@ -59,15 +59,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 +94,45 @@ 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();
$encode = new Encode();
$encode->setParams($params);

switch ($encode->fm) {
case 'avif':
$encodedImage = $image->toAvif($encode->getQuality());
break;

case 'gif':
$encodedImage = $image->toGif($encode->getQuality());
break;

case 'png':
$encodedImage = $image->toPng($encode->getQuality());
break;

case 'webp':
$encodedImage = $image->toWebp($encode->getQuality());
break;

case 'tiff':
$encodedImage = $image->toTiff($encode->getQuality());
break;

case 'jpg':
case 'pjpg':
default:
$encodedImage = $image->toJpeg($encode->getQuality());
break;
}

return $encodedImage->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
{
}
15 changes: 8 additions & 7 deletions src/Manipulators/Background.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;
use League\Glide\Manipulators\Helpers\Color;

/**
Expand All @@ -13,11 +13,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 +26,10 @@ 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);
// TODO: Find a way to communicate the mime
Art4 marked this conversation as resolved.
Show resolved Hide resolved
// $new->mime = $image->mime;
$image = $new->place($image, 'top-left', 0, 0);
}

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
Loading