Are there any best practices for handling image processing functions like MagickResizeImage in PHP to avoid exceeding the execution time limit?

When handling image processing functions like MagickResizeImage in PHP, it's important to optimize the code to avoid exceeding the execution time limit. One way to do this is by setting a higher maximum execution time limit using set_time_limit() function or by increasing the memory limit using ini_set('memory_limit', '256M'). Additionally, you can optimize the image processing code itself by resizing images in batches or using more efficient algorithms.

// Set a higher maximum execution time limit
set_time_limit(60);

// Increase memory limit
ini_set('memory_limit', '256M');

// Example code for resizing images using MagickResizeImage
$image = new Imagick('image.jpg');
$image->resizeImage(200, 200, Imagick::FILTER_LANCZOS, 1);
$image->writeImage('resized_image.jpg');
$image->destroy();