Skip to content

Commit 8db04de

Browse files
authored
Merge pull request #18 from ace-of-aces/feat/image-drivers-support
[Docs + Test] Properly support multiple image drivers
2 parents 6f593e9 + 595ca6a commit 8db04de

File tree

14 files changed

+102
-39
lines changed

14 files changed

+102
-39
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Please review these guidelines before submitting any pull requests.
1919

2020
## 1. Package Development
2121

22+
> ![CAUTION]
23+
> For package testing, both `GD` and `Imagick` drivers must be installed and enabled.
24+
2225
### Setup
2326

2427
Clone your fork, then install the dev dependencies:

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"spatie/laravel-package-tools": "^1.16"
2626
},
2727
"require-dev": {
28+
"ext-gd": "*",
29+
"ext-imagick": "*",
2830
"larastan/larastan": "^3.0",
2931
"laravel/pint": "^1.14",
3032
"league/flysystem-aws-s3-v3": "^3.0",

docs/pages/available-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ blur=50
3232
```
3333

3434
> [!CAUTION]
35-
> The `blur` option is a resource-intensive operation and may cause memory issues if the image is too large. It is recommended to use this option with caution and test beforehand, or disable it in the config.
35+
> When using the default GD driver, `blur` is very resource-intensive and may cause memory issues if the image is too large. We recommend the [Imagick driver](/installation#driver-configuration) if you want to use this option, or else to leave it disabled in the config.
3636
3737
## `contrast`
3838

docs/pages/installation.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,12 @@
44

55
- PHP \>= 8.4
66
- Laravel 12.x
7-
- [GD PHP Library](https://www.php.net/manual/en/book.image.php)
7+
- [GD](https://www.php.net/manual/en/book.image.php) or [Imagick](https://www.php.net/manual/en/book.imagick.php) PHP extension installed and [enabled](#driver-configuration)
88

99
::: tip
1010
If you want to use the file caching feature (highly recommended), a configured `Storage` disk and a `Cache` driver is required. More info in the [Image Caching](/image-caching) section.
1111
:::
1212

13-
### Important `php.ini` settings❗
14-
1. The underlying image processing library (GD) can use alot more RAM than regular web requests. It's highly recommended to set your memory limit to *at least* 256MB.
15-
```
16-
memory_limit=512M
17-
```
18-
2. If you have the [Swoole extension](https://laravel.com/docs/octane#swoole) installed, make sure you have the following setting to [avoid conflicts](https://github.com/ace-of-aces/laravel-image-transform-url/issues/4) with Laravel's `defer` helper which this package uses.
19-
```
20-
swoole.use_shortname=off
21-
```
22-
2313
## Installation
2414

2515
Install the package via composer:
@@ -33,3 +23,24 @@ Publish the config file with:
3323
```bash
3424
php artisan vendor:publish --tag="image-transform-url-config"
3525
```
26+
27+
## Driver Configuration
28+
29+
To use Imagick instead of the default GD library for image processing (recommended for performance), you will have to [change the default image driver](https://image.intervention.io/v3/getting-started/frameworks#application-wide-configuration) for the underlying [Intervention Image](https://image.intervention.io/) package.
30+
31+
::: info
32+
The [`libvips` driver](https://github.com/Intervention/image-driver-vips) is currently not supported.
33+
:::
34+
35+
## PHP Settings
36+
37+
Depending on your environment, you may need to adjust some `php.ini` settings.
38+
39+
1. If you are using the default GD driver, be aware that it can use alot more RAM than regular web requests. It's highly recommended to set your memory limit to *at least* 256MB.
40+
```
41+
memory_limit=512M
42+
```
43+
2. If you have the [Swoole extension](https://laravel.com/docs/octane#swoole) installed, make sure you have the following setting to [avoid conflicts](https://github.com/ace-of-aces/laravel-image-transform-url/issues/4) with Laravel's `defer` helper which this package uses.
44+
```
45+
swoole.use_shortname=off
46+
```

testbench.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ workbench:
2323
config: true
2424
build:
2525
- asset-publish
26-
- create-sqlite-db
27-
- db-wipe
28-
- migrate-fresh
2926
- storage-link
3027
assets:
3128
- test-assets

tests/Feature/CacheTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
]));
8989

9090
$disk = Storage::disk(config()->string('image-transform-url.cache.disk'));
91-
$size = $disk->size($this->getCacheEndPath('test-data', 'cat.jpg', ['width' => 1200, 'version' => $i]));
91+
$size = $disk->size($this->getCacheEndPath('images', 'cat.jpg', ['width' => 1200, 'version' => $i]));
9292

9393
$totalSizeMB += $size / (1024 * 1024);
9494

@@ -144,7 +144,7 @@
144144
]));
145145

146146
$disk = Storage::disk(config()->string('image-transform-url.cache.disk'));
147-
$endPath = $this->getCacheEndPath('test-data', 'cat.jpg', ['width' => 1200, 'version' => $i]);
147+
$endPath = $this->getCacheEndPath('images', 'cat.jpg', ['width' => 1200, 'version' => $i]);
148148

149149
$cacheFilePaths[] = $endPath;
150150

@@ -173,7 +173,7 @@
173173
'path' => 'cat.jpg',
174174
]));
175175

176-
$lastCacheFilePath = $this->getCacheEndPath('test-data', 'cat.jpg', ['width' => 2400, 'version' => 99]);
176+
$lastCacheFilePath = $this->getCacheEndPath('images', 'cat.jpg', ['width' => 2400, 'version' => 99]);
177177

178178
$finalResponse->assertOk();
179179
$finalResponse->assertHeader('X-Cache', 'MISS');

tests/Feature/OptionsTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
beforeEach(function () {
1010
Cache::flush();
1111
Storage::fake(config()->string('image-transform-url.cache.disk'));
12-
});
12+
})->with([
13+
function () {
14+
config()->set('image.driver', \Intervention\Image\Drivers\Gd\Driver::class);
15+
16+
return 'gd';
17+
},
18+
function () {
19+
config()->set('image.driver', \Intervention\Image\Drivers\Imagick\Driver::class);
20+
21+
return 'imagick';
22+
},
23+
]);
1324

1425
it('can process the height option', function () {
1526
/** @var TestCase $this */

tests/Feature/S3SourceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
it('can serve from an s3 disk source directory', function () {
2222
/** @var TestCase $this */
2323
$imagePath = 'images/test.jpg';
24-
Storage::disk('s3')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
24+
Storage::disk('s3')->put($imagePath, file_get_contents(public_path('images/cat.jpg')));
2525

2626
$response = $this->get(route('image.transform', [
2727
'options' => 'width=100',
@@ -40,7 +40,7 @@
4040
config()->set('image-transform-url.default_source_directory', 's3');
4141

4242
$imagePath = 'images/test.jpg';
43-
Storage::disk('s3')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
43+
Storage::disk('s3')->put($imagePath, file_get_contents(public_path('images/cat.jpg')));
4444

4545
$response = $this->get(route('image.transform.default', [
4646
'options' => 'width=100',

tests/Feature/SignedUrlTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ function configureTestEnvironment(): void
1616
{
1717
config()->set('image-transform-url.signed_urls.enabled', true);
1818
config()->set('image-transform-url.signed_urls.for_source_directories', ['protected']);
19-
config()->set('image-transform-url.source_directories', [
20-
'test-data' => public_path('test-data'),
21-
'protected' => Storage::fake('local')->path('protected'),
22-
]);
19+
config()->set('image-transform-url.source_directories.protected', Storage::fake('local')->path('protected'));
2320
}
2421

2522
it('can protect a route with a signed URL', function () {
2623
/** @var TestCase $this */
2724
configureTestEnvironment();
2825

29-
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('test-data/cat.jpg')));
26+
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('images/cat.jpg')));
3027

3128
assert(Storage::disk('local')->exists('protected/cat.jpg'));
3229

@@ -53,7 +50,7 @@ function configureTestEnvironment(): void
5350
/** @var TestCase $this */
5451
configureTestEnvironment();
5552

56-
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('test-data/cat.jpg')));
53+
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('images/cat.jpg')));
5754

5855
assert(Storage::disk('local')->exists('protected/cat.jpg'));
5956

@@ -80,7 +77,7 @@ function configureTestEnvironment(): void
8077
/** @var TestCase $this */
8178
configureTestEnvironment();
8279

83-
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('test-data/cat.jpg')));
80+
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('images/cat.jpg')));
8481

8582
assert(Storage::disk('local')->exists('protected/cat.jpg'));
8683

@@ -103,7 +100,7 @@ function configureTestEnvironment(): void
103100

104101
config()->set('image-transform-url.default_source_directory', 'protected');
105102

106-
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('test-data/cat.jpg')));
103+
Storage::disk('local')->put('protected/cat.jpg', file_get_contents(public_path('images/cat.jpg')));
107104

108105
assert(Storage::disk('local')->exists('protected/cat.jpg'));
109106

tests/Feature/SourceDirectoriesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
it('can serve from the storage directory', function () {
1616

1717
$imagePath = 'images/test.jpg';
18-
Storage::disk('public')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
18+
Storage::disk('public')->put($imagePath, file_get_contents(public_path('images/cat.jpg')));
1919

2020
$response = $this->get(route('image.transform', [
2121
'options' => 'width=100',
@@ -34,7 +34,7 @@
3434
config()->set('image-transform-url.default_source_directory', 'storage');
3535

3636
$imagePath = 'images/test.jpg';
37-
Storage::disk('public')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
37+
Storage::disk('public')->put($imagePath, file_get_contents(public_path('images/cat.jpg')));
3838

3939
$response = $this->get(route('image.transform.default', [
4040
'options' => 'width=100',

0 commit comments

Comments
 (0)