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/

时间: 2024-09-29 15:47:08

IMAGES RE-SIZE IN MAGENTO的相关文章

Magento 后台不能登录

  经常有人遇到magento后台,输入了正确的账号密码.不能正常登陆,也不提示错误.就是继续跳转到登陆界面. 网上有很多解决的文章,大多是把某段代码给注释掉. 我的是独立服务器,按照网上的方法,注释了代码后,同样不能登陆. 后来我清空了cache 和 session后.能登陆了.但是只是暂时的.过了几十分钟.重新登陆,又出现问题了. 所以问题出现在给var分配内存空间上面. 在对magento优化的时候.我使用了命令mount -t tmpfs -o size=100M,mode=0777 t

WHY YOU SHOULDN&amp;#39;T MERGE JAVASCRIPT IN MAGENTO

Most people - myself included - thought that merging all of your separate Javascript files was a healthy way to speed up the front end of your site. The logic was that by merging the files, you reduce the number of requests the browser makes when loa

Magento Adminhtml Form

开发Magento后台的时候经常用到表单(Varien_Data_Form),下面是所有表单元素的添加方法: 非必填 注释掉 Java代码   'class'     => 'required-entry',   'required'  => true,   1.input type='text' Java代码   $fieldset->addField('title', 'text', array(       'label'     => 'Title3',       'cl

Magento数据库配置选项,以及mysql 读写分离

1.数据库配置 [mysqld] key_buffer = 512M max_allowed_packet = 64M table_cache = 512 sort_buffer_size = 4M read_buffer_size = 4M read_rnd_buffer_size = 2M myisam_sort_buffer_size = 64M tmp_table_size = 128M query_cache_size = 96M query_cache_type = 1 thread

magento性能优化的教程(非常详细)

前面优化 mod_deflate模块,将text. css 和 javascript 先进行压缩再发送到浏览器.这样就会减少网络下载量,缩短等待时间,示例如下: # Insert filter on all content     SetOutputFilter DEFLATE     # Insert filter on selected content types only     AddOutputFilterByType DEFLATE text/html text/plain text

Magento认证工程师考试及注册流程

Magento公司在2011年下半年推出了Magento认证工程师考试, 其分为两个级别Magento Certified Developer和The Magento Certified Developer Plus, 费用都是一样的每科$260. 至于通过考试的好处,我在这里就不多说了, 有兴趣的同学可以看这里: http://www.magentocommerce.com/certification/的关于Benefits描述. 据公司老大4月分参加一年一度的Magento大会" Imagi

Magento加速利器——lazyload

  Magento的速度是令人头疼的问题,我现在介绍一种前端的加速方法.说到lazyload,相信很多人都不陌生,现在很多网站都已经用到这个技术,他可以延迟加载长页面的图片.对于Magento这样的商城网站的加速就很明显了.我今天说的这个lazyload是经过POPO改造的(强逼我给他加外连--).下面我放一些测试的数据,我正在做的一个网站的列表页. 很明显的就能看出差距.接下来写下用法: 首先加上jQuery,lazyload两段js. lazyload: (function($) { $.f

阿里云 CDN HTTPS 最佳实践——TLS record size(五)

原理 TLS 协议由两层协议组成:TLS 握手协议和 TLS 记录协议(TLS Record),TLS Record 协议在 TLS 握手协议之下.下面是 SSL/TLS 的分层结构: 所有的 TLS 上层数据(包含 TLS 握手协议消息以及更上层的应用协议数据)都由 TLS Record 来封装和传输.下面是 TLS Record 协议的消息封装流程: 一个消息会在 TLS Record 协议层被分段,然后对每个分段分别压缩(已废弃)和加密,最后加上 TLS Record 协议头再通过网络层发

magento根据距离计算运费模块

问题描述 magento根据距离计算运费模块 首先我是菜鸟,基本上不会php.但是已经摸索magento两个月,多少能看懂点php代码,以及magento的整个框架.我现在需要做的是配置一个根据距离计算运费的模块,比如三公里内五块钱,三公里外十块钱.我想知道有没有magento大神做过类似的工作,可否给点指导性意见!!!!