在 Wordpress 中加载相同宽高比的缩略图

问题描述 投票:0回答:0

我已经在 WordPress 中注册了具有特定宽高比的风景图像的尺寸(2048 像素 x 684 像素);

add_image_size( '2048x684-header', 2048, 684, true); //crop.

我已将 ACF 图像字段设置为返回一个图像 ID,我正在调用图像使用;

wp_get_attachment_image( $image, '2048x684-header' );

假设纵横比是;
xxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxx

如果原件≥2048 像素,该函数仅生成缩略图,这意味着如果尺寸小于 2048,则使用与所需纵横比不成比例的下一个缩略图尺寸。在我的例子中,使用了 1170x684 的缩略图,即

xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx

我正在寻找一种方法来为该特定纵横比生成多个缩略图,即如果我上传的原始图像小于 2024 宽,它将生成尺寸较小但纵横比相同的比例图像,例如1600 像素 x 534 像素。

我尝试添加具有相同纵横比的不同尺寸,例如;

add_image_size( '1600x534-header', 1600, 534, true); //crop. Smaller but same aspect ratio.
add_image_size( '1100x367-header', 1100, 367, true); //crop. Smaller but same aspect ratio.

这不能作为后备。有没有办法设置图像后备,即如果较大的缩略图不可用,则使用指定的下一个?

wordpress advanced-custom-fields thumbnails aspect-ratio responsive-images
© www.soinside.com 2019 - 2024. All rights reserved.