$original_image_size = api_getimagesize($image);//run each once we view thumbnails is too heavy, then need move into !file_exists($image_thumbnail, and only run when haven't the thumbnail
$original_image_size = api_getimagesize($image);//it isn't heavey here because thumbnails are already created. Here only for no gif, jpg, or png image files. But if there are many image files no supported can be heavy here too.
if (in_array($imagetype,$allowed_thumbnail_types)&& $original_image_size['width']>$max_thumbnail_width || $original_image_size['height']>$max_thumbnail_height) {
if (in_array($imagetype,$allowed_thumbnail_types)) {
if (!file_exists($image_thumbnail)) {
$original_image_size = api_getimagesize($image);//run each once we view thumbnails is too heavy, then need move into !file_exists($image_thumbnail, and only run when haven't the thumbnail