static function from_thumbnail($post_id, $width = 200, $height = 200)
{
$images = array();
$post = get_post($post_id);
if (!empty($post->post_password)) {
return $images;
}
if (!function_exists('get_post_thumbnail_id')) {
return $images;
}
$thumb = get_post_thumbnail_id($post_id);
if ($thumb) {
$meta = wp_get_attachment_metadata($thumb);
// Must be larger than requested minimums
if (!isset($meta['width']) || $meta['width'] < $width) {
return $images;
}
if (!isset($meta['height']) || $meta['height'] < $height) {
return $images;
}
$too_big = !empty($meta['width']) && $meta['width'] > 1200 || !empty($meta['height']) && $meta['height'] > 1200;
if ($too_big && (method_exists('Jetpack', 'is_module_active') && Jetpack::is_module_active('photon') || defined('WPCOM') && IS_WPCOM)) {
$img_src = wp_get_attachment_image_src($thumb, array(1200, 1200));
} else {
$img_src = wp_get_attachment_image_src($thumb, 'full');
}
$url = $img_src[0];
$images = array(array('type' => 'image', 'from' => 'thumbnail', 'src' => $url, 'src_width' => $img_src[1], 'src_height' => $img_src[2], 'href' => get_permalink($thumb)));
}
if (empty($images) && (defined('IS_WPCOM') && IS_WPCOM)) {
$meta_thumbnail = get_post_meta($post_id, '_jetpack_post_thumbnail', true);
if (!empty($meta_thumbnail)) {
if (!isset($meta_thumbnail['width']) || $meta_thumbnail['width'] < $width) {
return $images;
}
if (!isset($meta_thumbnail['height']) || $meta_thumbnail['height'] < $height) {
return $images;
}
$images = array(array('type' => 'image', 'from' => 'thumbnail', 'src' => $meta_thumbnail['URL'], 'src_width' => $meta_thumbnail['width'], 'src_height' => $meta_thumbnail['height'], 'href' => $meta_thumbnail['URL']));
}
}
return $images;
}