博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IMAGES RE-SIZE IN MAGENTO
阅读量:6237 次
发布时间:2019-06-22

本文共 3412 字,大约阅读时间需要 11 分钟。

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://ugkia.baihongyu.com/

你可能感兴趣的文章
使用jQuery和ajax代替iframe
查看>>
Keepalived + nginx实现高可用性和负载均衡
查看>>
Git整理
查看>>
12 个 CSS 高级技巧汇总
查看>>
Hibernate中 Restrictions.or()和Restrictions.disjunction()区别
查看>>
org.apache.commons.net.ftp包开发FTP客户端,实现断点续传,中文支持
查看>>
springmvc笔记--配置文件简述
查看>>
git 提交本地代码
查看>>
判断图中两个结点间是否有特定长度的路径
查看>>
Yii2.0 rules验证规则集合的详细介绍
查看>>
世界最好编程语言之父来华,约吗?
查看>>
RSA和MD5加密
查看>>
Swift 中的利刃,函数和闭包
查看>>
iOS开发之顶部状态栏statusBar颜色变化小结
查看>>
sql高级用法
查看>>
mysql安装
查看>>
Web前端开发规范(二)
查看>>
uva 621 - Secret Research
查看>>
MAC快捷键
查看>>
动态代理模式
查看>>