IMAGES RE-SIZE IN MAGENTO

简介:

In this article I will show how to use re-size parameters of default Magento images re-size feature.

By default the re-size of the product images working in the following way:

1
2
<?php echo $this ->helper( 'catalog/image' )
             ->init( $_product , 'small_image' )->resize(135); ?>

The code generate the 135х135px image. There are a number of additional parameters that control the image output, here is a list of these parameters with default values:

1
2
3
4
5
6
7
8
9
<?php
     echo  $this ->helper( 'catalog/image' )->init( $_product , 'small_image' )
             ->constrainOnly(false)
             ->keepAspectRatio(true)
             ->keepFrame(true)
             ->keepTransparency(true)
             ->backgroundColor( array (255,255,255))
             ->resize(135, 135);
?>

1 - "Small image" parameter.

There are three types of product images in Magento:

  • Thumbnail
  • Small Image
  • Base Image

Each type have its own image, it allows to load different images for small thumbnail or for big image.

2 - "constrainOnly" parameter.

If the "constrainOnly" parameter is set to true, in this case the images which are smaller than specified value will be not enlarged by Magento. Only border of such images will increase. This is useful if you have small product images and you don't like when Magento pixelate them. This option will not effect images which are bigger than specified value. Example:

3 - "keepAspectRatio" parameter.

If the "keepAspectRatio" parameter is set to true, in this case the proportions of the image will not be modified. Example:

4 - "keepFrame" parameter.

The "keepFrame" parameter guarantees that the image will be not cropped. When "keepAspectRatio" is false the "keepFrame" will not work. Example:

5 - "keepTransparency" parameter.

The "keepTransparency" parameter keep the transparent background of the images. If the "keepTransparency" parameter is set to false, in this case such images will have white background (by default). You can set any color for the background using the backgroundColor parameter. Example:

6 - "backgroundColor" parameter.

The "backgroundColor" allows to set any color as image background. You can enter a color as a RGB code, example: backgroundColor(array(255,255,255)). If the "keepTransparency" parameter is set to true, in this case the background will be not applied to the images with transparency. Example:

7 - "resize" parameter.

Using the "resize" parameter you can set a fixed width and height size for the image. If only one size value is entered and "keepFrame" parameter is set to true, in this case the image height will be equal to the image width.

Examples of the parameters.

1) Fixed height, the width will be calculated automatically:

1
2
3
4
->constrainOnly(true)
->keepAspectRatio(true)
->keepFrame(false)
->resize(null, 135);

Please note that the "keepFrame" parameter is set to false, otherwise all images will be 135х135px.

2) Fixed width, the height will be calculated automatically:

1
2
3
4
->constrainOnly(true)
->keepAspectRatio(true)
->keepFrame(false)
->resize(135, null);

Other useful methods.

The following methods also could be useful:

1
2
3
4
5
6
<?php
     echo $this ->helper( 'catalog/image' )
         ->init( $_product , 'small_image' )->getOriginalWidth();
     echo $this ->helper( 'catalog/image' )
         ->init( $_product , 'small_image' )->getOriginalHeight();
?>

You can get the width and height of the original image, in case if you will need to do some extra calculations or re-size the image in some different way.

原文:http://astrio.net/blog/images-resize-in-magento/


目录
相关文章
|
12月前
|
传感器 监控 搜索推荐
智能纺织品:健康监测与生活方式的结合
【10月更文挑战第22天】智能纺织品融合了传感器、导电纤维和微电子元件等先进技术,不仅改变了穿着体验,还为健康监测和生活方式的改善带来了新机遇。它们能实时监测心率、血压等生理数据,通过无线通信技术传输至手机或云端,实现远程监控与数据分析。未来,智能纺织品将更加智能化、个性化和环保,成为日常生活中不可或缺的一部分。
|
数据采集 搜索推荐 安全
做谷歌独立站多少钱?
答案是:做谷歌独立站是3000元。 当你想在谷歌上创建一个独立站点,你可能会想知道这需要多少费用。 以下内容将为你详细解释与创建谷歌独立站点相关的费用。 初始建站费用 首先,你需要购买一个域名。 通常,一个域名的价格会在10元至200元之间,这取决于域名的流行度和后缀。 接下来,你可能需要一个主机来托管你的网站,这通常每月会花费你20元至200元。
784 0
做谷歌独立站多少钱?
|
前端开发 Android开发
React Native 离线包/图片资源
1). 打包 进入项目根目录(如图1,anubis为项目名)执行命令 react-native bundle --platform android --dev false --entry-file index.
1797 0
|
存储 Android开发
方法:一键把一堆手机号码一次性快速导入手机通讯录
手机是人们日常沟通常用的工具,所以自然就要用到手机里面的通讯录联系。因此我们常要把别人的号码存入到手机通讯录里面,如果只是存五个十个那就动动手指就可以了。但是如果你想存把一个电脑excel表格里面的几百个、几千个、几万个等数量级别的联系人一键导入手机通讯录,显然手动一个个来存入是不现实的。我这里演示,通过借助网上常见的便捷工具软件,金芝号码提取导入助手,代替你手动工作来快速完成这个工作,如何一键把一堆手机号码一次性快速导入手机通讯录,省事省时省力。下面做个操作过程的图文讲解。
4653 0
方法:一键把一堆手机号码一次性快速导入手机通讯录
|
数据可视化 前端开发 JavaScript
Springboot构建Echarts数据可视化
pring boot集成了tomcat等容器,效率更高,要实现数据的可视化,需要构建spring Boot框架架构web项目。同时使用注意的方式,就可以轻松建立前端访问路径与后端controller方法的映射关系,而不用像servlet一样维护繁琐的xml映射配置表。
911 0
Springboot构建Echarts数据可视化
|
机器学习/深度学习 人工智能 固态存储
又一家!天数智芯天垓100 产品卡与龙蜥操作系统完成产品兼容互认证
天数智芯天垓100 产品卡与龙蜥操作系统(Anolis OS)8 完成并通过相互兼容性测试认证,双方进行严格测试后,结果显示:相互兼容,功能正常,运行稳定。
又一家!天数智芯天垓100 产品卡与龙蜥操作系统完成产品兼容互认证
|
安全 物联网 数据安全/隐私保护
如何用30分钟快速优化家中Wi-Fi?阿里工程师有绝招
现代人离不开手机,更离不开Wi-Fi。很多同学经常吐槽家中Wi-Fi用得不爽,打游戏看视频又卡又慢。
35489 0
|
API Docker 容器
标签管理利器——使用标签编辑器,多地域多产品千台资源一次搞定
创建阿里云资源时,您可以给资源绑定标签。已经创建的资源,也可以在资源列表页面或者通过API,批量的添加、更改和删除标签。当遇到如下更为复杂问题和场景,该如何快速解决标签问题呢? 资源跨度大,需要跨资源类型、跨地域,将关联的资源打上标签。
3788 0
标签管理利器——使用标签编辑器,多地域多产品千台资源一次搞定
|
新零售 C++
阿里云正式推出分期付款服务:折上再分期,助您最高节省50%上云费用!
9月17日,阿里云分期付款(云分期)服务业务正式推出。作为业内首款面向企业客户在云电商采购的信用分期服务,云分期通过分析企业客户在阿里云官网消费情况,评估企业信用,向企业客户提供灵活便捷的分期服务。与自行向银行申请贷款相比较,其在信用额度、审批速度、审批材料、时间管理等方面,都更具吸引力。
7969 0
|
弹性计算 Linux Windows
【实操】云服务器ECS扩充磁盘、磁盘扩容
帮您快速掌握云服务器ECS如何扩充磁盘。
10995 0