LaravelPackages.net
Acme Inc.
Toggle sidebar
maximumadvertising/laravel-image-resize

Dynamically resize an image and returns the URL using Intervention and Storage

2.065
6
1.1.1
About maximumadvertising/laravel-image-resize

maximumadvertising/laravel-image-resize is a Laravel package for dynamically resize an image and returns the url using intervention and storage. It currently has 6 GitHub stars and 2.065 downloads on Packagist (latest version 1.1.1). Install it with composer require maximumadvertising/laravel-image-resize. Discover more Laravel packages by maximumadvertising or browse all Laravel packages to compare alternatives.

Last updated

Image Resize Helper for Laravel

Dynamically resize an image and returns the URL using Intervention and Storage

Latest Stable Version Latest Unstable Version

Require

  • Laravel 5 or 6
  • Intervention Image ^2.4

Supported Filesystem Drivers

  • Local
  • S3
  • Oss (Aliyun Cloud Storage)

Installation

This package can be installed through Composer.

composer require maximumadvertising/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'): 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') }}" />

sample output

<img src="https://localhost/thumbs/originalDir/fit/200x200/filename.jpg" />

Tests

Run tests with:

vendor/bin/phpunit

Star History Chart