函数文档

wp_shrink_dimensions()

💡 云策文档标注

概述

wp_shrink_dimensions() 函数用于计算图像缩小后的新尺寸,但自 WordPress 3.0.0 起已被弃用,建议改用 wp_constrain_dimensions()。

关键要点

  • 函数功能:基于当前图像尺寸和最大允许尺寸,计算缩小后的宽度和高度。
  • 参数说明:接受当前宽度、高度以及可选的最大宽度和高度(默认分别为 128 和 96)。
  • 返回值:返回一个包含新宽度和高度的数组。
  • 弃用状态:自 WordPress 3.0.0 起弃用,内部调用 wp_constrain_dimensions() 实现相同功能。

注意事项

在开发中应避免使用此函数,转而使用 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
$wmaxintoptional
Maximum wanted width

Default:128

$hmaxintoptional
Maximum wanted height

Default:96

Return

array Shrunk dimensions (width, height).

Source

function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
	_deprecated_function( __FUNCTION__, '3.0.0', 'wp_constrain_dimensions()' );
	return wp_constrain_dimensions( $width, $height, $wmax, $hmax );
}

Changelog

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