繁体   English   中英

从 magento 2 中的产品更改所有图像的自定义高度宽度

[英]change custom height width of all images from product in magento 2

我有 3 张特定产品的图片。 所有图像的大小不同。 所以我希望所有图像在获取时都具有相同的高度宽度。 我可以使用调整大小 function 来调整图像大小,但它只调整特定图像的大小而不是全部。 目前我正在使用它,它只给我产品基础图像的图像大小。 但我想要所有人

$this->_imageHelper->init($product, 'product_base_image' )->keepAspectRatio(TRUE)->constrainOnly(TRUE)->keepFrame(TRUE)->resize(270, 340)->getUrl() 

但我正在使用

$images = $product->getMediaGalleryImages(); 

if ($images instanceof \Magento\Framework\Data\Collection) {
            foreach ($images as $image) {
                if ($image->getMediaType() == 'image') {
                    $productImagesArray[] = $image->getUrl();
                } elseif ($image->getMediaType() == 'external-video') {
                    $videoUrl = (!empty($image->getVideoUrl())) ? $image->getVideoUrl() : $image->getVideoUrlDefault();
                }
            }
        }

我想用给定的高度宽度从这个for循环调整所有图像的大小

您可以创建一个 function 来调整大小并调用该 function 传递参数作为 'product_base_image' 和 'product_small_image'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM