Laravel PHP: Intervention Image

Category:
PHP
Tags:
Laravel
PHP

Krunal Patel
5 months ago

Introduction

Intervention Image is a PHP library for image handling and manipulation. With this library, you can manipulate various aspects of images within your application. It offers features such as image optimization, cropping, resizing, and much more. By leveraging the Intervention Image library, you can perform a wide range of image-related tasks with ease and efficiency.


Server Requirements

Before beginning the installation, please ensure that your environment meets the following requirements:

  •  PHP >= 8.1
  •  FileInfo Extension
  •  One of the following image libraries:
    • GD library (>=2.0) or  
    • Imagick PHP Extension (>=6.5)

By confirming that your server environment meets these requirements, you can proceed with the installation process smoothly.

Installation:


CMD: composer require intervention/image

* Create a route. 

Route::post('/image',[ImageController::class, 'store'])->name('image.store');

*  Add ImageManager class.
 -
Here, we can perform manipulation tasks such as resizing, grayscale conversion, fitting, cropping, and rotating, efficiently handling various image editing operations.


use Intervention\Image\ImageManager;

	public function store(Request $request){
        if($request->file('image')){
            $take_image = $request->file('image');
            $manage = new ImageManager(new Driver());
            $img_name
 = hexdec(uniqid()).'.'.$take_image->getClientOriginalExtension();
           // reading image 
		$img = $manage->read($take_image);
            $img = $img->resize(300, 250)->greyscale(12);
           // encoding jpeg data & store 
		$img->toJpeg(50)->save(public_path('profile/'. $img_name));  
        }
     }


Reference URL:
https://image.intervention.io/v3


Thank you for reading.


DevZone
Made by developer, Made for developers