Imagemagick - PHP批量转换缩略图没有服务器压力?

I've been using WPDM to create a file system for a client of mine. Unfortunately WPDM doesn't have any preview functionality for filetypes like psd, ai, pdf, etc so I've been trying to create this functionality myself by using ImageMagick.

I'm probably approaching this the wrong way, as I have a major issue with using the code. It only creates the first thumbnail (or two, depending on the psds file size) before it crashes with an Internal Server Error and even one thumbnail makes the site incredibly slow.

// Function to create preview images for all files in WPDM package
function create_previews() {
    $file_list = uploaded_files_path();
    $preview_image_path_list=array();

    foreach ($file_list as $file) {
        $imagick = new Imagick();
        $img = wp_get_image_editor($file);
        $imagick->readImage($file);
        $filenamelres = $img->generate_filename('thumb', ABSPATH.'wp-content/uploads/thumbs/', 'png' );

        if ( ! is_wp_error( $imagick ) ) {
            if ( ! file_exists($filenamelres) ) {
                $imagick->setIteratorIndex(0);
                $imagick->thumbnailImage(200, 0);
                $imagick->writeImage($filenamelres);
                $preview_image_path_list[] = $filenamelres;
            } else {}
        } else {
            $preview_image_path_list[] = $filenamelres;
        }

        $imagick->destroy(); 
    }

    return $preview_image_path_list;
}

Is there a different route to take here. Could I do the same without stressing the server as much as I'm doing?

As per my comment: on a system of any non-trivial size, thumbnails should be generated in the background, not within the web server process. Switch to cron or a job queue, and use a placeholder thumbnail in the meantime.

It's worth finding out what triggered the "Internal Server Error" though - you might need to turn up your error logging to ensure it is recorded.