【问题标题】:How to get thumbnail image in magento 2如何在magento 2中获取缩略图
【发布时间】:2016-12-26 13:49:14
【问题描述】:

我在 magento 2 中使用过此代码

$media_url = $storeObj->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$baseimage          = $media_url.'catalog/product' . $_product->getImage();  

Output: http://localhost/smithbuy/pub/media/catalog/product/w/d/wd7500aaks.jpg

But, I want 
http://localhost/smithbuy/pub/media/catalog/product/cache/1/image/700x700/e9c3970ab036de70892d86c6d221abfe/w/d/wd7500aaks.jpg

请帮帮我。

【问题讨论】:

  • $this->_imageHelper->init($product, 'product_page_image_small') ->setImageFile($image->getFile()) ->getUrl() 使用类似这样的东西

标签: magento magento-2.0


【解决方案1】:

使用以下代码在 Magento 中使用缩略图:

$Media = $product->getMediaGalleryEntries();
foreach ($Media as $image) {
    $image->getTypes();
}

getTypes() 返回一个可能包含以下值的数组:

  • 图片
  • small_image
  • 缩略图

如果它包含缩略图,那么它就是缩略图。

【讨论】:

    猜你喜欢
    • 2011-09-17
    • 2012-09-09
    • 2014-07-26
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2010-09-14
    • 1970-01-01
    相关资源
    最近更新 更多