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/


目录
相关文章
|
Cloud Native 关系型数据库 MySQL
直播预告 | PostgreSQL 内核解读系列第六讲:PostgreSQL 索引介绍(下)
本系列课程将面向DBA、高校学生、内核爱好者,分15个章节,系统化介绍PG核心技术原理、用法和代码实现。希望通过课程学习,让没有内核经验的同学和DBA,也可以进行简单的特性开发,更深入理解PG配置和运行原理。本节课将讲述 PostgreSQL 索引基本介绍,涵盖Hash索引、Bitmap索引、GiST索引、GIN索引、brin索引、其他索引等内容。
直播预告 | PostgreSQL 内核解读系列第六讲:PostgreSQL 索引介绍(下)
|
存储 Android开发
方法:一键把一堆手机号码一次性快速导入手机通讯录
手机是人们日常沟通常用的工具,所以自然就要用到手机里面的通讯录联系。因此我们常要把别人的号码存入到手机通讯录里面,如果只是存五个十个那就动动手指就可以了。但是如果你想存把一个电脑excel表格里面的几百个、几千个、几万个等数量级别的联系人一键导入手机通讯录,显然手动一个个来存入是不现实的。我这里演示,通过借助网上常见的便捷工具软件,金芝号码提取导入助手,代替你手动工作来快速完成这个工作,如何一键把一堆手机号码一次性快速导入手机通讯录,省事省时省力。下面做个操作过程的图文讲解。
4049 0
方法:一键把一堆手机号码一次性快速导入手机通讯录
新版直播OBS操作手册
云栖社区直播频道改版啦!新版直播OBS操作速速Get!
12374 1
新版直播OBS操作手册
|
人工智能 分布式计算 大数据
阿里开发者招聘节 | 2019阿里巴巴技术面试题集锦!参考答案已公布!
阿里巴巴资深技术专家们结合多年的工作、面试经验总结提炼而成的笔试真题这一次将陆续放出(面试题答案将在专辑分享结束后统一汇总分享)。并通过这些笔试真题开放阿里巴巴工作机会,让更多的开发者加入到阿里这个大平台。
|
安全 物联网 数据安全/隐私保护
如何用30分钟快速优化家中Wi-Fi?阿里工程师有绝招
现代人离不开手机,更离不开Wi-Fi。很多同学经常吐槽家中Wi-Fi用得不爽,打游戏看视频又卡又慢。
35268 0
|
弹性计算 Linux Windows
【实操】云服务器ECS扩充磁盘、磁盘扩容
帮您快速掌握云服务器ECS如何扩充磁盘。
10807 0
|
人工智能 文字识别 API
阿里云视觉智能开放平台使用简明教程
阿里云视觉智能开放平台是基于阿里巴巴视觉智能技术实践经验,面向视觉智能技术企业和开发商(含开发者),为其提供高易用、普惠的视觉API服务,帮助企业快速建立视觉智能技术应用能力的综合性视觉AI能力平台。首期公测阶段平台将主要开放人脸人体、文字识别、商品理解、内容安全、图像识别、图像增强、图像分割、目标检测8个类目等多个API能力供您使用。
3335 0
【从入门到放弃-SpringBoot】SpringBoot源码分析-请求过程
前言 前文【从入门到放弃-SpringBoot】SpringBoot源码分析-WebServer中以SpringBoot中内嵌的Tomcat为例了解了webserver的启动过程。 本文将分析下一条请求在SpringBoot中,从接受到返回都经历了那些过程。
3601 0
|
关系型数据库 RDS MySQL
【最佳实践】DTS轻松实现RDS for MySQL与阿里云Elasticsearch数据实时同步
本文介绍如何使用 DTS 快速创建RDS for MySQL->阿里云Elasticsearch的实时同步作业,实现RDS for MySQL数据到阿里云Elasticsearch的实时同步。
4266 0
SIGCOMM2019阿里巴巴首次发表两篇主会论文
经过多年的积累,阿里巴巴的网络研究和技术已经进入世界前列。今年阿里巴巴在SIGCOMM上实现了主会论文的历史性突破。
6197 0

热门文章

最新文章