function spb_getImageBySize($params = array('post_id' => NULL, 'attach_id' => NULL, 'thumb_size' => 'thumbnail')) { //array( 'post_id' => $post_id, 'thumb_size' => $grid_thumb_size ) if ((!isset($params['attach_id']) || $params['attach_id'] == NULL) && (!isset($params['post_id']) || $params['post_id'] == NULL)) { return; } $post_id = isset($params['post_id']) ? $params['post_id'] : 0; if ($post_id) { $attach_id = get_post_thumbnail_id($post_id); } else { $attach_id = $params['attach_id']; } $thumb_size = $params['thumb_size']; global $_wp_additional_image_sizes; $thumbnail = ''; if (is_string($thumb_size) && (!empty($_wp_additional_image_sizes[$thumb_size]) && is_array($_wp_additional_image_sizes[$thumb_size]) || in_array($thumb_size, array('thumbnail', 'thumb', 'medium', 'large', 'full')))) { //$thumbnail = get_the_post_thumbnail( $post_id, $thumb_size ); $thumbnail = wp_get_attachment_image($attach_id, $thumb_size); //TODO APPLY FILTER } if ($thumbnail == '' && $attach_id) { if (is_string($thumb_size)) { $thumb_size = str_replace(array('px', ' ', '*', '×'), array('', '', 'x', 'x'), $thumb_size); $thumb_size = explode("x", $thumb_size); } $p_img = ""; // Resize image to custom size if (isset($thumb_size[0]) && isset($thumb_size[1])) { $p_img = spb_resize($attach_id, null, $thumb_size[0], $thumb_size[1], true); } /*if ( spb_debug() ) { var_dump($p_img); }*/ if ($p_img != "") { $img_class = ''; //if ( $grid_layout == 'thumbnail' ) $img_class = ' no_bottom_margin'; class="'.$img_class.'" $thumbnail = '<img src="' . $p_img['url'] . '" width="' . $p_img['width'] . '" height="' . $p_img['height'] . '" />'; //TODO: APPLY FILTER } } $p_img_large = wp_get_attachment_image_src($attach_id, 'large'); return array('thumbnail' => $thumbnail, 'p_img_large' => $p_img_large); }
function spb_getImageBySize($params = array('post_id' => null, 'attach_id' => null, 'thumb_size' => 'thumbnail')) { //array( 'post_id' => $post_id, 'thumb_size' => $grid_thumb_size ) if ((!isset($params['attach_id']) || $params['attach_id'] == null) && (!isset($params['post_id']) || $params['post_id'] == null)) { return; } $post_id = isset($params['post_id']) ? $params['post_id'] : 0; if ($post_id) { $attach_id = get_post_thumbnail_id($post_id); } else { $attach_id = $params['attach_id']; } $thumb_size = $params['thumb_size']; global $_wp_additional_image_sizes; $thumbnail = ''; if (is_string($thumb_size) && (!empty($_wp_additional_image_sizes[$thumb_size]) && is_array($_wp_additional_image_sizes[$thumb_size]) || in_array($thumb_size, array('thumbnail', 'thumb', 'medium', 'large', 'full')))) { $thumbnail = wp_get_attachment_image($attach_id, $thumb_size); //TODO APPLY FILTER } $p_img = $p_img_small = ""; if ($thumbnail == '' && $attach_id) { if (is_string($thumb_size)) { $thumb_size = str_replace(array('px', ' ', '*', '×'), array('', '', 'x', 'x'), $thumb_size); $thumb_size = explode("x", $thumb_size); } // Resize image to custom size if ($attach_id != "" && isset($thumb_size[0]) && isset($thumb_size[1])) { $p_img = spb_resize($attach_id, null, $thumb_size[0], $thumb_size[1], true); } $alt = trim(strip_tags(get_post_meta($attach_id, '_wp_attachment_image_alt', true))); if (empty($alt)) { $attachment = get_post($attach_id); if ($attachment) { $alt = trim(strip_tags($attachment->post_excerpt)); // If not, Use the Caption } } if (empty($alt)) { if ($attachment) { $alt = trim(strip_tags($attachment->post_title)); // Finally, use the title } } } if ($p_img != '') { $p_img_small = '<img src="' . $p_img['url'] . '" width="66" height="66" class="attachment-thumbnail" />'; } else { $img = wp_get_attachment_image_src($attach_id, 'thumbnail'); if (isset($img[0])) { $p_img_small = '<img src="' . $img[0] . '" width="66" height="66" class="attachment-thumbnail" />'; } } $p_img_large = wp_get_attachment_image_src($attach_id, 'large'); return array('thumbnail' => $thumbnail, 'p_img_large' => $p_img_large, 'p_img_small' => $p_img_small); }