magento2产品图片

本文介绍了Magento中如何定义图片类型(imagetype),设置图片尺寸(imagesize),以及如何指定图片效果的方法。通过调整themeview.xml文件,用户可以自定义产品图片的显示方式,包括宽度、高度和长宽比等。

什么是image type?

product允许上传多张image,某些image可能会用于特定用途,比如封面、结构图等,需要给特定图片定义一个应用名称以便区分用途,就叫image type。默认有Base Image, Small Image, Thumbnail,可以在images and videos中指定图片为某个image type。

怎么设置image size?

在theme view.xml,通常在

<theme_dir>/etc/view.xml

例如

app/design/frontend/Magento/blank/etc/view.xml

一般的配置代码

<images module="Magento_Catalog">
   <image id="category_page_list" type="small_image">
        <width>360</width>
        <height>656</height>
   </image>
<images/>

已经存在的image id已经被应用于系统中的某处,如果需要用代码提取如下

$imageHelper = $objectManager->get( 'Magento\Catalog\Helper\Image' );
$productImage = $imageHelper->init( $product, $image_id )
  ->constrainOnly( FALSE )
  ->keepAspectRatio( TRUE )
  ->keepFrame( FALSE )
  ->getUrl();

怎么增加image type?

只需要添加新的Attribute就可以
图片描述
图片描述
图片描述

怎么指定图片的效果?

<images module="Magento_Catalog">
   <image id="category_page_list" type="small_image">
        <width>360</width>
        <height>656</height>
        <aspect_ratio>true</aspect_ratio>
   </image>
<images/>

支持的效果比较有限,可以查代码获取所有的效果:Magento\Catalog\Helper\Image::setImageProperties()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值