Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4', '8.5']
php-version: ['8.3', '8.4', '8.5']
dependencies: [highest]
include:
- php-version: '8.1'
- php-version: '8.3'
dependencies: lowest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-cli
FROM php:8.3-cli

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
}
],
"require": {
"php": "^8.1",
"intervention/image": "^3.9.1",
"php": "^8.3",
"intervention/image": "^4.0",
"league/flysystem": "^3.0",
"psr/http-message": "^1.0|^2.0"
},
Expand Down
23 changes: 11 additions & 12 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace League\Glide\Api;

use Intervention\Image\Decoders\BinaryImageDecoder;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ImageManagerInterface;
use League\Glide\Manipulators\ManipulatorInterface;

class Api implements ApiInterface
Expand All @@ -21,7 +20,7 @@ class Api implements ApiInterface
/**
* Intervention image manager.
*/
protected ImageManager $imageManager;
protected ImageManagerInterface $imageManager;

/**
* Collection of manipulators.
Expand All @@ -45,11 +44,11 @@ class Api implements ApiInterface
/**
* Create API instance.
*
* @param ImageManager $imageManager Intervention image manager.
* @param array $manipulators Collection of manipulators.
* @param Encoder|null $encoder Image encoder.
* @param ImageManagerInterface $imageManager Intervention image manager.
* @param array $manipulators Collection of manipulators.
* @param Encoder|null $encoder Image encoder.
*/
public function __construct(ImageManager $imageManager, array $manipulators, ?Encoder $encoder = null)
public function __construct(ImageManagerInterface $imageManager, array $manipulators, ?Encoder $encoder = null)
{
$this->setImageManager($imageManager);
$this->setManipulators($manipulators);
Expand All @@ -60,19 +59,19 @@ public function __construct(ImageManager $imageManager, array $manipulators, ?En
/**
* Set the image manager.
*
* @param ImageManager $imageManager Intervention image manager.
* @param ImageManagerInterface $imageManager Intervention image manager.
*/
public function setImageManager(ImageManager $imageManager): void
public function setImageManager(ImageManagerInterface $imageManager): void
{
$this->imageManager = $imageManager;
}

/**
* Get the image manager.
*
* @return ImageManager Intervention image manager.
* @return ImageManagerInterface Intervention image manager.
*/
public function getImageManager(): ImageManager
public function getImageManager(): ImageManagerInterface
{
return $this->imageManager;
}
Expand Down Expand Up @@ -133,7 +132,7 @@ public function getEncoder(): Encoder
*/
public function run(string $source, array $params): string
{
$image = $this->imageManager->read($source, BinaryImageDecoder::class);
$image = $this->imageManager->decodeBinary($source);

foreach ($this->manipulators as $manipulator) {
$manipulator->setParams($params);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function run(ImageInterface $image): EncodedImageInterface
throw new \Exception("Invalid format provided: {$format}");
}

return $image->encodeByExtension($format, ...$encoderOptions);
return $image->encodeUsingFileExtension($format, ...$encoderOptions);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulators/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function run(ImageInterface $image): ImageInterface

return $image->driver()->createImage($image->width(), $image->height())
->fill($color)
->place($image, 'top-left', 0, 0)
->insert($image, 0, 0, 'top-left')
->setOrigin(
new Origin($image->origin()->mediaType())
);
Expand Down
22 changes: 10 additions & 12 deletions src/Manipulators/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function getDpr(): float
{
$dpr = $this->getParam('dpr');

if (!is_numeric($dpr)
if (
!is_numeric($dpr)
|| $dpr < 0
|| $dpr > 8
) {
Expand All @@ -137,17 +138,14 @@ public function getDpr(): float
*/
public function runOverlay(ImageInterface $image, float $width, string $color): ImageInterface
{
return $image->drawRectangle(
(int) round($width / 2),
(int) round($width / 2),
function (RectangleFactory $rectangle) use ($image, $width, $color) {
$rectangle->size(
(int) round($image->width() - $width),
(int) round($image->height() - $width),
);
$rectangle->border($color, intval($width));
}
);
return $image->drawRectangle(function (RectangleFactory $rectangle) use ($image, $width, $color) {
$rectangle->at((int) round($width / 2), (int) round($width / 2));
$rectangle->size(
(int) round($image->width() - $width),
(int) round($image->height() - $width),
);
$rectangle->border($color, intval($width));
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Manipulators/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function run(ImageInterface $image): ImageInterface
*/
public function runGreyscaleFilter(ImageInterface $image): ImageInterface
{
return $image->greyscale();
return $image->grayscale();
}

/**
Expand All @@ -50,7 +50,7 @@ public function runGreyscaleFilter(ImageInterface $image): ImageInterface
*/
public function runSepiaFilter(ImageInterface $image): ImageInterface
{
$image->greyscale()
$image->grayscale()
->brightness(-10)
->contrast(10)
->colorize(38, 27, 12)
Expand Down
7 changes: 4 additions & 3 deletions src/Manipulators/Flip.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Glide\Manipulators;

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

class Flip extends BaseManipulator
Expand All @@ -26,9 +27,9 @@ public function run(ImageInterface $image): ImageInterface

if (null !== $flip) {
return match ($flip) {
'both' => $image->flip()->flop(),
'v' => $image->flip(),
'h' => $image->flop(),
'both' => $image->flip(Direction::HORIZONTAL)->flip(Direction::VERTICAL),
'v' => $image->flip(Direction::VERTICAL),
'h' => $image->flip(Direction::HORIZONTAL),
default => $image,
};
}
Expand Down
9 changes: 5 additions & 4 deletions src/Manipulators/Orientation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Glide\Manipulators;

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

class Orientation extends BaseManipulator
Expand All @@ -26,12 +27,12 @@ public function run(ImageInterface $image): ImageInterface

if ('auto' === $orientation) {
return match ($image->exif('Orientation')) {
2 => $image->flip(),
2 => $image->flip(Direction::VERTICAL),
3 => $image->rotate(180),
4 => $image->rotate(180)->flip(),
5 => $image->rotate(270)->flip(),
4 => $image->rotate(180)->flip(Direction::VERTICAL),
5 => $image->rotate(270)->flip(Direction::VERTICAL),
6 => $image->rotate(270),
7 => $image->rotate(90)->flip(),
7 => $image->rotate(90)->flip(Direction::VERTICAL),
8 => $image->rotate(90),
default => $image,
};
Expand Down
11 changes: 6 additions & 5 deletions src/Manipulators/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace League\Glide\Manipulators;

use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Color;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Size as ImageSize;

class Size extends BaseManipulator
{
Expand Down Expand Up @@ -159,7 +160,7 @@ public function resolveMissingDimensions(ImageInterface $image, ?int $width = nu
}

if (is_null($width) || is_null($height)) {
$size = (new Rectangle($image->width(), $image->height()))
$size = (new ImageSize($image->width(), $image->height()))
->scale($width, $height);

$width = $size->width();
Expand Down Expand Up @@ -299,7 +300,7 @@ public function runMaxResize(ImageInterface $image, int $width, int $height): Im
*/
public function runFillResize(ImageInterface $image, int $width, int $height): ImageInterface
{
return $image->pad($width, $height, 'transparent');
return $image->containDown($width, $height, Color::transparent()->toString());
}

/**
Expand All @@ -313,7 +314,7 @@ public function runFillResize(ImageInterface $image, int $width, int $height): I
*/
public function runFillMaxResize(ImageInterface $image, int $width, int $height): ImageInterface
{
return $image->contain($width, $height, 'transparent');
return $image->contain($width, $height, Color::transparent()->toString());
}

/**
Expand Down Expand Up @@ -349,7 +350,7 @@ public function runCropResize(ImageInterface $image, int $width, int $height): I

[$offset_x, $offset_y] = $this->resolveCropOffset($image, $width, $height);

return $image->crop($width, $height, $offset_x, $offset_y, 'transparent');
return $image->crop($width, $height, $offset_x, $offset_y, Color::transparent()->toString());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Manipulators/Watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function run(ImageInterface $image): ImageInterface
]);
$watermark = $size->run($watermark);

return $image->place($watermark, $markpos, intval($markx), intval($marky), $markalpha);
return $image->insert($watermark, intval($markx), intval($marky), $markpos, $markalpha);
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ public function getImage(ImageInterface $image): ?ImageInterface
if ($this->watermarks->fileExists($path)) {
$source = $this->watermarks->read($path);

$mark = $image->driver()->handleInput($source);
$mark = $image->driver()->decodeImage($source);
}
} catch (FilesystemV2Exception $exception) {
throw new FilesystemException('Could not read the image `'.$path.'`.');
Expand Down
17 changes: 10 additions & 7 deletions src/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace League\Glide;

use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageManagerInterface;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\Local\LocalFilesystemAdapter;
Expand Down Expand Up @@ -229,21 +232,21 @@ public function getEncoder(): ?Encoder
/**
* Get Intervention image manager.
*
* @return ImageManager Intervention image manager.
* @return ImageManagerInterface Intervention image manager.
*/
public function getImageManager(): ImageManager
public function getImageManager(): ImageManagerInterface
{
$driver = 'gd';

if (isset($this->config['driver'])) {
$driver = $this->config['driver'];
}

return match ($driver) {
'gd' => ImageManager::gd(),
'imagick' => ImageManager::imagick(),
default => ImageManager::withDriver($driver),
};
return ImageManager::usingDriver(match ($driver) {
'gd' => GdDriver::class,
'imagick' => ImagickDriver::class,
default => $driver,
});
}

/**
Expand Down
11 changes: 6 additions & 5 deletions tests/Api/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Glide\Api;

use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
Expand All @@ -16,7 +17,7 @@ class ApiTest extends TestCase

public function setUp(): void
{
$this->api = new Api(ImageManager::gd(), []);
$this->api = new Api(ImageManager::usingDriver(Driver::class), []);
}

public function tearDown(): void
Expand All @@ -31,7 +32,7 @@ public function testCreateInstance(): void

public function testSetImageManager(): void
{
$this->api->setImageManager(ImageManager::gd());
$this->api->setImageManager(ImageManager::usingDriver(Driver::class));
$this->assertInstanceOf(ImageManager::class, $this->api->getImageManager());
}

Expand Down Expand Up @@ -69,7 +70,7 @@ public function testGetApiParams(): void
$mock->shouldReceive('getApiParams')->andReturn(['foo', 'baz']);
});

$api = new Api(ImageManager::gd(), [$manipulator1, $manipulator2]);
$api = new Api(ImageManager::usingDriver(Driver::class), [$manipulator1, $manipulator2]);
$this->assertEquals(array_merge(Api::GLOBAL_API_PARAMS, ['foo', 'bar', 'baz']), $api->getApiParams());
}

Expand All @@ -80,12 +81,12 @@ public function testRun(): void
$mock->shouldReceive('mediaType')->andReturn('image/png');
}));

$mock->shouldReceive('encodeByExtension')->with('png')->andReturn(\Mockery::mock(EncodedImageInterface::class, function ($mock) {
$mock->shouldReceive('encodeUsingFileExtension')->with('png')->andReturn(\Mockery::mock(EncodedImageInterface::class, function ($mock) {
$mock->shouldReceive('toString')->andReturn('encoded');
}));
});

$manager = ImageManager::gd();
$manager = ImageManager::usingDriver(Driver::class);

$manipulator = \Mockery::mock(ManipulatorInterface::class, function ($mock) use ($image) {
$mock->shouldReceive('setParams')->with([]);
Expand Down
Loading
Loading