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



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

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

但我正在使用

$images = $product->getMediaGalleryImages(); 
if ($images instanceof MagentoFrameworkDataCollection) {
foreach ($images as $image) {
if ($image->getMediaType() == 'image') {
$productImagesArray[] = $image->getUrl();
} elseif ($image->getMediaType() == 'external-video') {
$videoUrl = (!empty($image->getVideoUrl())) ? $image->getVideoUrl() : $image->getVideoUrlDefault();
}
}
}

我想以给定的高度宽度调整此循环中的所有图像的大小

你能创建一个函数来调整大小并调用该函数,将参数作为"product_base_image"传递为"product_small_image">

最新更新