函数文档

wp_expand_dimensions()

💡 云策文档标注

概述

wp_expand_dimensions() 函数基于提供的示例宽度和高度,返回在最大宽度和高度限制下的最大可能尺寸。它通过调用 wp_constrain_dimensions() 实现,主要用于处理嵌入内容的尺寸扩展。

关键要点

  • 函数接受四个整数参数:示例宽度、示例高度、最大宽度和最大高度。
  • 返回一个包含两个整数的数组,分别表示最大宽度和最大高度(以像素为单位)。
  • 内部实现将示例尺寸乘以一个大数(1000000)后调用 wp_constrain_dimensions() 来计算结果。
  • 与 wp_constrain_dimensions() 相关,后者用于计算下采样图像的新尺寸。
  • 自 WordPress 2.9.0 版本引入。

代码示例

function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) {
	$example_width  = (int) $example_width;
	$example_height = (int) $example_height;
	$max_width      = (int) $max_width;
	$max_height     = (int) $max_height;

	return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );
}

📄 原文内容

Based on a supplied width/height example, returns the biggest possible dimensions based on the max width/height.

Description

See also

Parameters

$example_widthintrequired
The width of an example embed.
$example_heightintrequired
The height of an example embed.
$max_widthintrequired
The maximum allowed width.
$max_heightintrequired
The maximum allowed height.

Return

int[] An array of maximum width and height values.

  • 0 int
    The maximum width in pixels.
  • 1 int
    The maximum height in pixels.

Source

function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) {
	$example_width  = (int) $example_width;
	$example_height = (int) $example_height;
	$max_width      = (int) $max_width;
	$max_height     = (int) $max_height;

	return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );
}

Changelog

Version Description
2.9.0 Introduced.