What is the most efficient way to rename multiple images using a PHP script?

When renaming multiple images using a PHP script, the most efficient way is to use a loop to iterate through each image file and rename them accordingly. This can be achieved by using functions like scandir() to get a list of image files in a directory, and then using the rename() function to rename each file.

$directory = "path/to/images/";
$files = scandir($directory);

foreach($files as $file){
    if(in_array(pathinfo($file, PATHINFO_EXTENSION), ['jpg', 'png', 'jpeg'])){ //check if file is an image
        $newName = "new_image_" . uniqid() . "." . pathinfo($file, PATHINFO_EXTENSION); //generate new file name
        rename($directory . $file, $directory . $newName); //rename file
    }
}