ACF 设置画廊缩略图自定义尺寸

ACF set gallery thumbnail custom sizes

这是 php ACF Gallery 的代码

              <?php 

                $gallery = get_field('slider_1_gallery');

                if( $gallery ): 

                    ?>
                    <div class="big_slider">
                        <?php foreach( $gallery as $index=>$image ): ?>
                            <div class="slide">
                                <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                            </div>
                        <?php endforeach; ?>
                    </div>
                    <div class="miniature_slider">
                        <?php foreach( $gallery as $index=>$image ): ?>
                            <div class="slide">
                                <a href="<?php echo $image['url']; ?>" class="miniature" data-fancybox = "1">
                                    <img src="<?php echo  $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                                    <div class="mask">
                                        <i class="icon_1"></i>
                                    </div>
                                </a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>

缩略图有默认大小。但我需要为这些图片自定义尺寸

<img src="<?php echo  $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />

怎么设置 宽度 = 165 像素 高度 = 110 像素 在 ACF 画廊? 可以用缩放和裁剪来做到这一点吗?

如果您想提供自定义尺寸,请将此代码添加到 function.php:

<?php
    add_image_size( 'people-img', 360, 360, true ); 
?>

之后你需要像这样获取:

<?php
        $attachment_id = get_field('bio_image');
        $size = "people-img"; // (thumbnail, medium, large, full or custom size)
        $image = wp_get_attachment_image_src( $attachment_id, $size );
        // url = $image[0];
        // width = $image[1];
        // height = $image[2];
?>

<img src="<?php echo $image[0]; ?>" >