salahmyn / laravel-image-resize
Dynamically resize an image and returns the URL using Intervention and Storage
Requires
- php: ^7.2
- illuminate/cache: ^6.0
- illuminate/config: ~6.0
- illuminate/support: ^6.0
- intervention/image: ^2.4
- league/flysystem: ~1.0
Requires (Dev)
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-04-27 16:53:00 UTC
README
Fork from MaximumAdvertising/laravel-image-resize
Dynamically resize an image and returns the URL using Intervention and Storage
Require
- Laravel 5+
- Intervention Image ^2.4
Supported Filesystem Drivers
- Local
- S3
- Oss (Aliyun Cloud Storage)
Installation
This package can be installed through Composer.
composer require salahmyn/laravel-image-resize
For Laravel 5.4 and lower, you'll have to register the service provider and alias manually.
Add to service providers
Mxmm\ImageResize\ImageResizeServiceProvider::class,
And alias
'ImageResize' => Mxmm\ImageResize\Facade::class,
Publish config and assets (Optional)
php artisan vendor:publish --provider="Mxmm\ImageResize\ImageResizeServiceProvider"
Usage
Accepted parameters:
/** * @param string|null $path * @param int|null $width * @param int|null $height * @param string $action * @return string */ public static function url(string $path = null, int $width = null, int $height = null, string $action = 'fit' , $disk = null): string
In HTML:
<img src="{{ ImageResize::url('originalDir/filename.jpg', width, height, [action]) }}" />
Fit (resize & crop) an image to 200x200px
<img src="{{ ImageResize::url('originalDir/filename.jpg', 200, 200, 'fit') }}" />
Resize an image to 200x200px
<img src="{{ ImageResize::url('originalDir/filename.jpg', 200, 200, 'resize') }}" />
Fit (resize & crop) an image to 200px width, with auto height
<img src="{{ ImageResize::url('originalDir/filename.jpg', 200, null, 'fit') }}" />
Fit (resize & crop) an image to 200px width, with auto height
<img src="{{ ImageResize::url('originalDir/filename.jpg', 200, null, 'fit') }}" />
sample output
<img src="https://localhost/thumbs/originalDir/fit/200x200/filename.jpg" />
alias [asset]
an assets
drive in config filesystems
is required to use asset
method which handle files in public
directory
<?php return [ /* |----------------------------------------------- | Default Filesystem Disk |----------------------------------------------- | */ // ... 'disks' => [ // ... 'assets' => [ 'driver' => 'local', 'root' => public_path('assets'), ], ];
In HTML:
<img src="{{ ImageResize::asset('originalDir/filename.jpg', width, height, [action]) }}" />
Tests
Run tests with:
vendor/bin/phpunit