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
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Please review these guidelines before submitting any pull requests.

## 1. Package Development

> ![CAUTION]
> For package testing, both `GD` and `Imagick` drivers must be installed and enabled.

### Setup

Clone your fork, then install the dev dependencies:
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"spatie/laravel-package-tools": "^1.16"
},
"require-dev": {
"ext-gd": "*",
"ext-imagick": "*",
"larastan/larastan": "^3.0",
"laravel/pint": "^1.14",
"league/flysystem-aws-s3-v3": "^3.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/available-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ blur=50
```

> [!CAUTION]
> 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.
> 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.

## `contrast`

Expand Down
33 changes: 22 additions & 11 deletions docs/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@

- PHP \>= 8.4
- Laravel 12.x
- [GD PHP Library](https://www.php.net/manual/en/book.image.php)
- [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)

::: tip
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.
:::

### Important `php.ini` settings❗
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.
```
memory_limit=512M
```
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.
```
swoole.use_shortname=off
```

## Installation

Install the package via composer:
Expand All @@ -33,3 +23,24 @@ Publish the config file with:
```bash
php artisan vendor:publish --tag="image-transform-url-config"
```

## Driver Configuration

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.

::: info
The [`libvips` driver](https://github.com/Intervention/image-driver-vips) is currently not supported.
:::

## PHP Settings

Depending on your environment, you may need to adjust some `php.ini` settings.

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.
```
memory_limit=512M
```
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.
```
swoole.use_shortname=off
```
3 changes: 0 additions & 3 deletions testbench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ workbench:
config: true
build:
- asset-publish
- create-sqlite-db
- db-wipe
- migrate-fresh
- storage-link
assets:
- test-assets
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
]));

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

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

Expand Down Expand Up @@ -144,7 +144,7 @@
]));

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

$cacheFilePaths[] = $endPath;

Expand Down Expand Up @@ -173,7 +173,7 @@
'path' => 'cat.jpg',
]));

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

$finalResponse->assertOk();
$finalResponse->assertHeader('X-Cache', 'MISS');
Expand Down
13 changes: 12 additions & 1 deletion tests/Feature/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
beforeEach(function () {
Cache::flush();
Storage::fake(config()->string('image-transform-url.cache.disk'));
});
})->with([
function () {
config()->set('image.driver', \Intervention\Image\Drivers\Gd\Driver::class);

return 'gd';
},
function () {
config()->set('image.driver', \Intervention\Image\Drivers\Imagick\Driver::class);

return 'imagick';
},
]);

it('can process the height option', function () {
/** @var TestCase $this */
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/S3SourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
it('can serve from an s3 disk source directory', function () {
/** @var TestCase $this */
$imagePath = 'images/test.jpg';
Storage::disk('s3')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
Storage::disk('s3')->put($imagePath, file_get_contents(public_path('images/cat.jpg')));

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

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

$response = $this->get(route('image.transform.default', [
'options' => 'width=100',
Expand Down
13 changes: 5 additions & 8 deletions tests/Feature/SignedUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ function configureTestEnvironment(): void
{
config()->set('image-transform-url.signed_urls.enabled', true);
config()->set('image-transform-url.signed_urls.for_source_directories', ['protected']);
config()->set('image-transform-url.source_directories', [
'test-data' => public_path('test-data'),
'protected' => Storage::fake('local')->path('protected'),
]);
config()->set('image-transform-url.source_directories.protected', Storage::fake('local')->path('protected'));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/SourceDirectoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it('can serve from the storage directory', function () {

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

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

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

$response = $this->get(route('image.transform.default', [
'options' => 'width=100',
Expand Down
6 changes: 1 addition & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ protected function getEnvironmentSetUp($app)
protected function defineEnvironment($app)
{
tap($app['config'], function (Repository $config) {
$config->set('image-transform-url.source_directories', [
'test-data' => public_path('test-data'),
'storage' => Storage::fake('public')->path(''),
]);
$config->set('image-transform-url.default_source_directory', 'test-data');
$config->set('image-transform-url.source_directories.storage', Storage::fake('public')->path(''));
$config->set('image-transform-url.enabled_options', AllowedOptions::all());
});
}
Expand Down
2 changes: 1 addition & 1 deletion workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function register(): void
public function boot(): void
{
$this->publishes([
__DIR__.'/../../../workbench/test-data' => public_path('test-data'),
__DIR__.'/../../../workbench/test-data' => public_path('images'),
], 'test-assets');
}
}
4 changes: 2 additions & 2 deletions workbench/config/image-transform-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

'source_directories' => [
'images-test' => public_path('images'),
'images' => public_path('images'),
'storage' => storage_path('app/public/images'),
'remote' => ['disk' => 'r2'],
],
Expand All @@ -35,7 +35,7 @@
|
*/

'default_source_directory' => env('IMAGE_TRANSFORM_DEFAULT_SOURCE_DIRECTORY', 'images-test'),
'default_source_directory' => env('IMAGE_TRANSFORM_DEFAULT_SOURCE_DIRECTORY', 'images'),

/*
|--------------------------------------------------------------------------
Expand Down
46 changes: 46 additions & 0 deletions workbench/config/image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Image Driver
|--------------------------------------------------------------------------
|
| Intervention Image supports “GD Library” and “Imagick” to process images
| internally. Depending on your PHP setup, you can choose one of them.
|
| Included options:
| - \Intervention\Image\Drivers\Gd\Driver::class
| - \Intervention\Image\Drivers\Imagick\Driver::class
|
*/

'driver' => \Intervention\Image\Drivers\Imagick\Driver::class,

/*
|--------------------------------------------------------------------------
| Configuration Options
|--------------------------------------------------------------------------
|There are alifrazimar.
| These options control the behavior of Intervention Image.
|
| - "autoOrientation" controls whether an imported image should be
| automatically rotated according to any existing Exif data.
|
| - "decodeAnimation" decides whether a possibly animated image is
| decoded as such or whether the animation is discarded.
|
| - "blendingColor" Defines the default blending color.
|
| - "strip" controls if meta data like exif tags should be removed when
| encoding images.
*/

'options' => [
'autoOrientation' => true,
'decodeAnimation' => true,
'blendingColor' => 'ffffff',
'strip' => false,
],
];