函数文档

get_udims()

💡 云策文档标注

概述

get_udims() 是一个已弃用的 WordPress 函数,用于计算图像缩小后的新尺寸。它已被 wp_constrain_dimensions() 替代,并固定将图像约束到 128x96 像素。

关键要点

  • 函数已弃用:自 WordPress 3.5.0 起,建议使用 wp_constrain_dimensions() 替代。
  • 功能:基于当前宽度和高度,返回缩小后的尺寸数组(宽度, 高度)。
  • 参数:接受两个必需整数参数 $width 和 $height,分别表示图像的当前宽度和高度。
  • 返回值:返回一个包含新宽度和高度的数组。
  • 内部实现:调用 wp_constrain_dimensions() 并固定最大尺寸为 128x96 像素。

注意事项

在开发中应避免使用此函数,改用 wp_constrain_dimensions() 以保持代码兼容性和遵循最佳实践。


📄 原文内容

Calculates the new dimensions for a downsampled image.

Description

See also

Parameters

$widthintrequired
Current width of the image
$heightintrequired
Current height of the image

Return

array Shrunk dimensions (width, height).

Source

function get_udims( $width, $height ) {
	_deprecated_function( __FUNCTION__, '3.5.0', 'wp_constrain_dimensions()' );
	return wp_constrain_dimensions( $width, $height, 128, 96 );
}

Changelog

Version Description
3.5.0 Deprecated. Use wp_constrain_dimensions()
2.0.0 Introduced.