What are some recommended PHP libraries or tools for image resizing and cropping?

When working with images in PHP, it is often necessary to resize and crop images to fit specific dimensions or aspect ratios. To achieve this, you can use PHP libraries or tools that provide functions for image resizing and cropping. Some recommended libraries for image resizing and cropping in PHP include Intervention Image and Imagine.

// Using Intervention Image library for image resizing and cropping
require 'vendor/autoload.php'; // Include the Composer autoloader

use Intervention\Image\ImageManager;

// Create an instance of the ImageManager
$imageManager = new ImageManager();

// Load the image file
$image = $imageManager->make('path/to/image.jpg');

// Resize the image to specific dimensions
$image->resize(300, 200);

// Crop the image to a specific aspect ratio
$image->fit(150, 150);

// Save the modified image
$image->save('path/to/save/image.jpg');