【问题标题】:change custom height width of all images from product in magento 2从magento 2中的产品更改所有图像的自定义高度宽度
【发布时间】:2020-05-15 09:45:46
【问题描述】:

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

$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循环调整所有图像的大小

【问题讨论】:

    标签: php magento2 magento2.1


    【解决方案1】:

    你可以创建一个函数来调整大小并调用该函数,将参数传递为“product_base_image”和“product_small_image”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多