当前位置: 首页>>代码示例>>PHP>>正文


PHP wpb_resize函数代码示例

本文整理汇总了PHP中wpb_resize函数的典型用法代码示例。如果您正苦于以下问题:PHP wpb_resize函数的具体用法?PHP wpb_resize怎么用?PHP wpb_resize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wpb_resize函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wpb_getImageBySize

function wpb_getImageBySize( $params = array( 'post_id' => NULL, 'attach_id' => NULL, 'thumb_size' => 'thumbnail', 'class' => '' ) ) {
	//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'];
	$thumb_class = ( isset( $params['class'] ) && $params['class'] != '' ) ? $params['class'] . ' ' : '';

	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, false, array( 'class' => $thumb_class . 'attachment-' . $thumb_size ) );
		// TODO: APPLY FILTER
	} elseif ( $attach_id ) {
		if ( is_string( $thumb_size ) ) {
			preg_match_all( '/\d+/', $thumb_size, $thumb_matches );
			if ( isset( $thumb_matches[0] ) ) {
				$thumb_size = array();
				if ( count( $thumb_matches[0] ) > 1 ) {
					$thumb_size[] = $thumb_matches[0][0]; // width
					$thumb_size[] = $thumb_matches[0][1]; // height
				} elseif ( count( $thumb_matches[0] ) > 0 && count( $thumb_matches[0] ) < 2 ) {
					$thumb_size[] = $thumb_matches[0][0]; // width
					$thumb_size[] = $thumb_matches[0][0]; // height
				} else {
					$thumb_size = false;
				}
			}
		}
		if ( is_array( $thumb_size ) ) {
			// Resize image to custom size
			$p_img = wpb_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 );
				$alt = trim( strip_tags( $attachment->post_excerpt ) ); // If not, Use the Caption
			}
			if ( empty( $alt ) )
				$alt = trim( strip_tags( $attachment->post_title ) ); // Finally, use the title
			if ( $p_img ) {
				$img_class = '';
				//if ( $grid_layout == 'thumbnail' ) $img_class = ' no_bottom_margin'; class="'.$img_class.'"
				$thumbnail = '<img class="' . $thumb_class . '" src="' . $p_img['url'] . '" width="' . $p_img['width'] . '" height="' . $p_img['height'] . '" alt="' . $alt . '" />';
				//TODO: APPLY FILTER
			}
		}
	}

	$p_img_large = wp_get_attachment_image_src( $attach_id, 'large' );
	return array( 'thumbnail' => $thumbnail, 'p_img_large' => $p_img_large );
}
开发者ID:verbazend,项目名称:AWFA,代码行数:57,代码来源:helpers.php

示例2: wpb_getImageBySize

function wpb_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);
        }
        // Resize image to custom size
        $p_img = wpb_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);
            $alt = trim(strip_tags($attachment->post_excerpt));
            // If not, Use the Caption
        }
        if (empty($alt)) {
            $alt = trim(strip_tags($attachment->post_title));
        }
        // Finally, use the title
        /*if ( wpb_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'] . '" alt="' . $alt . '" />';
            //TODO: APPLY FILTER
        }
    }
    $p_img_large = wp_get_attachment_image_src($attach_id, 'large');
    return array('thumbnail' => $thumbnail, 'p_img_large' => $p_img_large);
}
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:50,代码来源:helpers.php

示例3: wpb_getImageBySize

/**
 * @param array $params
 *
 * @since 4.2
 * vc_filter: vc_wpb_getimagesize - to override output of this function
 * @return array|bool
 */
function wpb_getImageBySize($params = array())
{
    $params = array_merge(array('post_id' => null, 'attach_id' => null, 'thumb_size' => 'thumbnail', 'class' => ''), $params);
    if (!$params['thumb_size']) {
        $params['thumb_size'] = 'thumbnail';
    }
    if (!$params['attach_id'] && !$params['post_id']) {
        return false;
    }
    $post_id = $params['post_id'];
    $attach_id = $post_id ? get_post_thumbnail_id($post_id) : $params['attach_id'];
    $attach_id = apply_filters('vc_object_id', $attach_id);
    $thumb_size = $params['thumb_size'];
    $thumb_class = isset($params['class']) && '' !== $params['class'] ? $params['class'] . ' ' : '';
    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')))) {
        $attributes = array('class' => $thumb_class . 'attachment-' . $thumb_size);
        $thumbnail = wp_get_attachment_image($attach_id, $thumb_size, false, $attributes);
    } elseif ($attach_id) {
        if (is_string($thumb_size)) {
            preg_match_all('/\\d+/', $thumb_size, $thumb_matches);
            if (isset($thumb_matches[0])) {
                $thumb_size = array();
                if (count($thumb_matches[0]) > 1) {
                    $thumb_size[] = $thumb_matches[0][0];
                    // width
                    $thumb_size[] = $thumb_matches[0][1];
                    // height
                } elseif (count($thumb_matches[0]) > 0 && count($thumb_matches[0]) < 2) {
                    $thumb_size[] = $thumb_matches[0][0];
                    // width
                    $thumb_size[] = $thumb_matches[0][0];
                    // height
                } else {
                    $thumb_size = false;
                }
            }
        }
        if (is_array($thumb_size)) {
            // Resize image to custom size
            $p_img = wpb_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)));
            $attachment = get_post($attach_id);
            if (!empty($attachment)) {
                $title = trim(strip_tags($attachment->post_title));
                if (empty($alt)) {
                    $alt = trim(strip_tags($attachment->post_excerpt));
                    // If not, Use the Caption
                }
                if (empty($alt)) {
                    $alt = $title;
                }
                // Finally, use the title
                if ($p_img) {
                    $attributes = vc_stringify_attributes(array('class' => $thumb_class, 'src' => $p_img['url'], 'width' => $p_img['width'], 'height' => $p_img['height'], 'alt' => $alt, 'title' => $title));
                    $thumbnail = '<img ' . $attributes . ' />';
                }
            }
        }
    }
    $p_img_large = wp_get_attachment_image_src($attach_id, 'large');
    return apply_filters('vc_wpb_getimagesize', array('thumbnail' => $thumbnail, 'p_img_large' => $p_img_large), $attach_id, $params);
}
开发者ID:JPodz,项目名称:harlequinnejuice,代码行数:71,代码来源:helpers.php

示例4: wpb_getImageBySize

function wpb_getImageBySize($params = array('post_id' => NULL, 'attach_id' => NULL, 'thumb_size' => 'thumbnail', 'grid_columns_count' => 2, 'grid_with_sidebar' => 0))
{
    //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($post_id, $thumb_size);
        //TODO APPLY FILTER
    }
    $thumb_size = str_replace(array('px', ' ', '*'), array('', '', 'x'), $thumb_size);
    if (is_string($thumb_size) && !strpos($thumb_size, 'x') && !(!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')))) {
        $thumb_width_s = array(0 => array(1 => '900', 2 => '440', 3 => '287', 4 => '210', 5 => '60'), 1 => array(1 => '660', 2 => '320', 3 => '208', 4 => '158'));
        $thumb_width = $thumb_width_s[$params['grid_with_sidebar']][intval($params['grid_columns_count'])];
        $thumb_size = intval($params['grid_columns_count']) == 5 ? $thumb_width : $thumb_size;
        //            $thumb_size = str_replace(array( 'px', ' ', '*', '×' ), array( '', '', 'x', 'x' ), $thumb_size);
        $thumb_size = str_replace(array('px', ' ', '*', '×'), array('', '', '', ''), $thumb_size);
        //            $thumb_size = explode("x", $thumb_size);
        $thumb_size = array($thumb_width, $thumb_size);
    } else {
        if (strpos($thumb_size, 'x')) {
            list($thumb_width, $thumb_size) = split('[x]', $thumb_size);
        } else {
            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')))) {
                $thumb_size = str_replace(array('px', ' ', '*', '×'), array('', '', '', ''), $thumb_size);
                $thumb_width = get_option($thumb_size . '_size_w') == '' ? '150' : get_option($thumb_size . '_size_w');
                $thumb_size = get_option($thumb_size . '_size_h') == '' ? '150' : get_option($thumb_size . '_size_h');
            } else {
            }
        }
        $thumb_size = array($thumb_width, $thumb_size);
        // $post_id=='' and thumbnail==''   repair error
    }
    if ($thumbnail == '' && $attach_id) {
        // Resize image to custom size
        $p_img = wpb_resize($attach_id, null, $thumb_size[0], $thumb_size[1], true);
        /*if ( wpb_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');
        $p_img_large = $p_img_large[0];
    } else {
        // START - Themeton Additional
        $tt_image = get_post_image() ? get_post_image() : get_post_content_image();
        if ($tt_image) {
            $img_class = '';
            $thumbnail = '<img src="' . $tt_image . '" width="' . $thumb_size[0] . '" height="' . $thumb_size[1] . '" />';
            //TODO: APPLY FILTER
        }
        $p_img_large = $tt_image;
        // END   - Themeton Additional
    }
    //$p_img_large = wp_get_attachment_image_src($attach_id, 'large' );
    return array('thumbnail' => $thumbnail, 'p_img_large' => $p_img_large);
}
开发者ID:earthshakira,项目名称:rachanasansad-portfolio,代码行数:71,代码来源:helpers.php

示例5: ult_img_single_init

 /**   Filter for image uploader
  * 
  * @args    null|null
  *     or   null|URL
  *     or   ID|URL
  * @return  array|json
  *-------------------------------------------------*/
 function ult_img_single_init($content = null, $data = '', $size = 'full')
 {
     $final = '';
     if ($content != '' && $content != 'null|null') {
         //  Create an array
         $mainStr = explode('|', $content);
         $string = '';
         $mainArr = array();
         if (!empty($mainStr) && is_array($mainStr)) {
             foreach ($mainStr as $key => $value) {
                 if (!empty($value)) {
                     array_push($mainArr, $value);
                 }
             }
         }
         if ($data != '') {
             switch ($data) {
                 case 'url':
                     // First  - Priority for ID
                     if (!empty($mainArr[0]) && $mainArr[0] != 'null') {
                         $Image_Url = '';
                         //  Get image URL, If input is number - e.g. 100x48 / 140x40 / 350x53
                         if (preg_match('/^\\d/', $size) === 1) {
                             $size = explode('x', $size);
                             //  resize image using vc helper function - wpb_resize
                             $img = wpb_resize($mainArr[0], null, $size[0], $size[1], true);
                             if ($img) {
                                 $Image_Url = $img['url'];
                                 // $img['width'], $img['height'],
                             }
                         } else {
                             //  Get image URL, If input is string - [thumbnail, medium, large, full]
                             $hasImage = wp_get_attachment_image_src($mainArr[0], $size);
                             // returns an array
                             $Image_Url = $hasImage[0];
                         }
                         if (isset($Image_Url) && !empty($Image_Url)) {
                             $final = $Image_Url;
                         } else {
                             //  Second - Priority for URL - get {image from url}
                             if (isset($mainArr[1])) {
                                 $final = get_url($mainArr[1]);
                             }
                         }
                     } else {
                         //  Second - Priority for URL - get {image from url}
                         if (isset($mainArr[1])) {
                             $final = get_url($mainArr[1]);
                         }
                     }
                     break;
                 case 'json':
                     $final = json_encode($mainArr);
                     break;
                 case 'sizes':
                     $img_size = getImageSquereSize($img_id, $img_size);
                     $img = wpb_getImageBySize(array('attach_id' => $img_id, 'thumb_size' => $img_size, 'class' => 'vc_single_image-img'));
                     $final = $img;
                     break;
                 case 'array':
                 default:
                     $final = $mainArr;
                     break;
             }
         }
     }
     return $final;
 }
开发者ID:VitaAprel,项目名称:mynotebook,代码行数:75,代码来源:Ultimate_Image_Single.php


注:本文中的wpb_resize函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。