What are some PHP libraries or tools that can be used to batch process images in terms of cropping and scaling?

When batch processing images in PHP, it is common to need to crop and scale images to specific dimensions. This can be achieved using libraries or tools that provide functions for image manipulation. One popular library for image processing in PHP is "GD" (Graphics Draw), which provides functions for cropping and resizing images.

// Example of using GD library to batch process images by cropping and scaling

// Specify the directory containing images to be processed
$directory = 'path/to/images/';

// Get all files in the directory
$files = glob($directory . '*');

// Loop through each file
foreach ($files as $file) {
    // Open the image
    $image = imagecreatefromjpeg($file);

    // Get the current dimensions of the image
    $width = imagesx($image);
    $height = imagesy($image);

    // Set the desired dimensions for cropping and scaling
    $newWidth = 200;
    $newHeight = 200;

    // Create a new image with the desired dimensions
    $newImage = imagecreatetruecolor($newWidth, $newHeight);

    // Crop and scale the image to fit the new dimensions
    imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

    // Save the processed image
    imagejpeg($newImage, $directory . 'processed_' . basename($file));

    // Free up memory
    imagedestroy($image);
    imagedestroy($newImage);
}