^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_intermediate_image_sizes()用法示例

get_intermediate_image_sizes()

Gets the available intermediate image sizes.


描述


返回值

(array) Returns a filtered array of image size strings.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


源代码

File: wp-includes/media.php

function get_intermediate_image_sizes() {
	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
	$image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes
	if ( ! empty( $_wp_additional_image_sizes ) ) {
		$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
	}

	/**
	 * Filters the list of intermediate image sizes.
	 *
	 * @since 2.5.0
	 *
	 * @param array $image_sizes An array of intermediate image sizes. Defaults
	 *                           are 'thumbnail', 'medium', 'medium_large', 'large'.
	 */
	return apply_filters( 'intermediate_image_sizes', $image_sizes );
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/media.php:
    wp_get_additional_image_sizes()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/media.php:
    intermediate_image_sizes

Used By

  • wp-includes/widgets/class-wp-widget-media-image.php:
    WP_Widget_Media_Image::get_instance_schema()
  • wp-includes/widgets/class-wp-widget-media-image.php:
    WP_Widget_Media_Image::render_media()
  • wp-admin/includes/image-edit.php:
    wp_restore_image()
  • wp-admin/includes/image-edit.php:
    wp_save_image()
  • wp-admin/includes/image.php:
    wp_generate_attachment_metadata()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by markcallen

    In the get_image_sizes() example above – note that since WordPress 4.4 there is a new size – ‘medium_large’.

    Include that in the array on line 13 to prevent errors.

  2. List available image sizes with width and height following

    
    /**
     * Get information about available image sizes
     */
    function get_image_sizes( $size = '' ) {
    
    	global $_wp_additional_image_sizes;
    
    	$sizes = array();
    	$get_intermediate_image_sizes = get_intermediate_image_sizes();
    
    	// Create the full array with sizes and crop info
    	foreach( $get_intermediate_image_sizes as $_size ) {
    		if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
    			$sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
    			$sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
    			$sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
    		} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
    			$sizes[ $_size ] = array( 
    				'width' => $_wp_additional_image_sizes[ $_size ]['width'],
    				'height' => $_wp_additional_image_sizes[ $_size ]['height'],
    				'crop' =>  $_wp_additional_image_sizes[ $_size ]['crop']
    			);
    		}
    	}
    
    	// Get only 1 size if found
    	if ( $size ) {
    		if( isset( $sizes[ $size ] ) ) {
    			return $sizes[ $size ];
    		} else {
    			return false;
    		}
    	}
    	return $sizes;
    }
    
    

    Some examples of use of this function:

    
    var_dump( get_image_sizes() );
    /*
    array(4) {
      ["thumbnail"]=>
      array(3) {
        ["width"]=>
        string(3) "150"
        ["height"]=>
        string(3) "150"
        ["crop"]=>
        bool(true)
      }
      ["medium"]=>
      array(3) {
        ["width"]=>
        string(3) "300"
        ["height"]=>
        string(3) "300"
        ["crop"]=>
        bool(false)
      }
      ["large"]=>
      array(3) {
        ["width"]=>
        string(4) "1024"
        ["height"]=>
        string(4) "1024"
        ["crop"]=>
        bool(false)
      }
      ["juliobox-size"]=>
      array(3) {
        ["width"]=>
        int(211)
        ["height"]=>
        int(279)
        ["crop"]=>
        bool(false)
      }
    }
    */
    
    var_dump( get_image_sizes( 'large' ) );
    /*
    array(3) {
      ["width"]=>
      int(1024)
      ["height"]=>
      int(1024)
      ["crop"]=>
      bool(false)
    }
    */
    
    var_dump( get_image_sizes( 'foo-bar' ) );
    /*
    bool(false)
    */
    
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈