Blog Detail

21

Nov
Optimize & store images in multiple sizes easily in Laravel cover image

arrow_back Optimize & store images in multiple sizes easily in Laravel

Laravel Image Handler is an awesome package that can be used to optimize and store images in multiple sizes easily.

Installation

You can install this package via composer by running this command in terminal

composer require codepane/laravel-image-handler

Run this command too publish:

php artisan vendor:publish --provider="codepane\LaravelImageHandler\ImageHandlerServiceProvider"

Configuration

After installation is done once you can see imagehandler.php under the config directory.
You can update dimensions, format, and quality as per your need from a configuration file.
You can also add a new dimension.

Usage

Let’s deep dive into this package for how to use it

Store Image
use ImageHandler;

public function store()
{
    // its takes the default file name as it is
    ImageHandler::store($request->file);

    // in 2nd argument you can pass your custom file name with or without the path
    ImageHandler::store($request->file, 'file_name_with_or_without_path');
}

Get Image

use ImageHandler;

public function get()
{
    // this will return the original image
    ImageHandler::get('original_file_name');

    // pass dimension as the second argument to get a specific dimension of the file
    ImageHandler::get('original_file_name', 'sm');
}

Delete Image

use ImageHandler;

public function delete()
{
    ImageHandler::delete('original_file_name');
}

For more details, please visit Github.

Closing Note

The team of Codebrisk Laravel developers is always ready to execute even your boldest ideas. Our expert team can design and develop any type of custom CRM solution, SAAS app, or e-commerce app to meet our customer’s needs and transform our customer’s experiences. Get in touch with our team to discuss your bespoke ideas and learn more about the next steps to launching cooperation.

Published at : 21-11-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project