钩子文档

wp_image_resize_identical_dimensions

💡 云策文档标注

概述

wp_image_resize_identical_dimensions 是一个 WordPress 过滤器,用于控制是否生成与原始图像尺寸相同的子尺寸图像。该过滤器允许开发者干预图像处理流程,避免不必要的尺寸复制。

关键要点

  • 过滤器名称:wp_image_resize_identical_dimensions
  • 作用:过滤是否生成尺寸与原始图像相同的子尺寸图像,忽略1px的舍入差异
  • 参数:$proceed(布尔值,过滤后的值)、$orig_w(原始图像宽度)、$orig_h(原始图像高度)
  • 默认值:false(默认不生成相同尺寸的子尺寸)
  • 引入版本:WordPress 5.3.0

代码示例

$proceed = (bool) apply_filters( 'wp_image_resize_identical_dimensions', false, $orig_w, $orig_h );

注意事项

  • 该过滤器在 image_resize_dimensions() 函数中使用,用于计算图像编辑器的调整尺寸
  • 1px的差异通常由舍入引起,会被忽略,以确保尺寸比较的准确性

📄 原文内容

Filters whether to proceed with making an image sub-size with identical dimensions with the original/source image. Differences of 1px may be due to rounding and are ignored.

Parameters

$proceedbool
The filtered value.
$orig_wint
Original image width.
$orig_hint
Original image height.

Source

$proceed = (bool) apply_filters( 'wp_image_resize_identical_dimensions', false, $orig_w, $orig_h );

Changelog

Version Description
5.3.0 Introduced.