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?