emil-zhivkov/image-resizer

There is no license information available for the latest version (dev-master) of this package.

resize images and keep aspect ration

dev-master 2018-12-11 07:35 UTC

This package is auto-updated.

Last update: 2025-06-11 21:48:48 UTC


README

resize existing images on server and save it in custom directory. You can use them later only with calling model property

This version works onli with photos stored in public directory

Install package

composer require emil-zhivkov/image-resizer @dev

config/app.php

 EmilZhivkov\ImageResizer\ImageResizerServiceProvider::class,

Publishing configuration file

php artisan vendor:publish

Configuration file config/image-resizer.php

Section 1

if you store in your database only filename you must define public path to your photo directory Example: image field: avatar.jpg 'images_base_path' => 'public_path_to_image_directory',

Or image field: images/users/avatar.jpg

'images_base_path' => '/'

Section 2

You can change image sizes here. Aspect ratio keep the same as original photo You can define sizes here. And you can add you own type of size but must to extend ImageTrait and add new mutator there.

Define model image property here Example

'User' => 'avatar',

'Article' => 'featured_image',

'Product' => 'image'

etc.

Section 3 define public path to your fallback images.

##Usage Exmple:

<?php

namespace App\Models;


use EmilZhivkov\ImageResizer\Traits\ImageTrait;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    use ImageTrait;
}
    $user = User::find($id);
    $user->small_avatar_image;
  

object property is combination of image_sizes key from configuration file config/image-resizer.php and '_image'

When you call objects image, if image exist will automatically return or module will resize and save new image in proper directory.

thats all folks, enjoy !