- 浏览: 13628996 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
magento图片处理 Customize Magento’s Image Resize Functionality
1. Customize Magento’s Image Resize Functionality
Need to remove the white border around your images? Don't want everything to be square? Here is how to customize the ->resize functionality in Magento.Here is what the default image resize code looks like:
<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(350) ?>
The problem is this will always give you a 350 x 350 pixel square. If your image is rectangular, you will get a white frame around it to make it square. The resize() command can be quickly and easily customized to work better with rectangular images.
->constrainOnly(true) This will not resize an image that is smaller than the dimensions inside the resize() part.
->keepAspectRatio(true) This will not distort the height/width of the image.
->keepFrame(false) This will not put a white frame around your image.
Here is what your image code would look like with all these set:
<?php echo $this->helper('catalog/image')->init($_product, 'image')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(350, null) ?>
This would resize your images to a max 350 width and constrain the height. If your image is taller than it is wide, you will end up with a nicely resized vertical image.
Here are the various places that images are used:
/app/design/frontend/default/yourtheme/catalog/product/view/media.phtml (displays the image on your product view page)
/app/design/frontend/default/yourtheme/catalog/product/list.phtml (displays the image on category view)
This has helped us out many times. Let us know in the comments if you use it!
from: http://www.magthemes.com/magento-blog/customize-magentos-image-resize-functionality/
2. Magento: Resize Image
You can resize image with fixed height and variable width. Or, you can resize with fixed width and variable height. Following code shows how you do it in Magento.
Fixed width of 600px
<?php echo $this->helper('catalog/image')->init($_product, 'image') ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(600,null) ?>
Fixed height of 600px
<?php echo $this->helper('catalog/image')->init($_product, 'image') ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(null,600) ?>
The following code will resize image proportionally and not let the image be greater than height and width specified.
<?php echo $this->helper('catalog/image')->init($_product, 'image') ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(400,400) ?>
Description of the functions used above:-
constrainOnly(bool $flag)
Guarantee, that image picture will not be bigger, than it was. Applicable before calling resize() It is false by default
keepAspectRatio(bool $flag)
Guarantee, that image picture width/height will not be distorted. Applicable before calling resize() It is true by default.
keepFrame(bool $flag)
Guarantee, that image will have dimensions, set in $width/$height.
Applicable before calling resize() Not applicable, if
keepAspectRatio(false).
You can resize image with Varien_Image class as well. This is most suitable when you are resizing image that is not related with catalog product.
// actual path of image $imageUrl = Mage::getBaseDir('media').DS."myimage".DS.$post->getThumbnail(); // path of the resized image to be saved // here, the resized image is saved in media/resized folder $imageResized = Mage::getBaseDir('media').DS."myimage".DS."resized".DS.$post->getThumbnail(); // resize image only if the image file exists and the resized image file doesn't exist // the image is resized proportionally with the width/height 135px if (!file_exists($imageResized)&&file_exists($_imageUrl)) : $imageObj = new Varien_Image($_imageUrl); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->resize(135, 135); $imageObj->save($imageResized); endif;
You can use the resized image now as:
<img src="<?php echo Mage::getBaseUrl('media')."myimage/resized/".$post->getThumbnail() ?>" />
Another Scenario
Suppose, you have an image link. Now, you want to resize it. The image might be from any place. In this example, I am supposing the image link to be like http://localhost/magento/media/catalog/category/test_image.jpg
Now, I have to resize it. To do so, I will create a directory called resized inside media/catalog/category . And, I will save the resized file into the newly created resized directory.
// my sample image $imageUrl = "http://localhost/magento/media/catalog/category/test_image.jpg"; // create folder if(!file_exists("./media/catalog/category/resized")) mkdir("./media/catalog/category/resized",0777); // get image name $imageName = substr(strrchr($imageUrl,"/"),1); // resized image path (media/catalog/category/resized/IMAGE_NAME) $imageResized = Mage::getBaseDir('media').DS."catalog".DS."category".DS."resized".DS.$imageName; // changing image url into direct path $dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($imageUrl,'/media')); // if resized image doesn't exist, save the resized image to the resized directory if (!file_exists($imageResized)&&file_exists($dirImg)) : $imageObj = new Varien_Image($dirImg); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->resize(120, 120); $imageObj->save($imageResized); endif; $newImageUrl = Mage::getBaseUrl('media')."catalog/category/resized/".$imageName;
Displaying newly created resized image.
<img src="<?php echo Mage::getBaseUrl('media')."catalog/category/resized/".$newImageUrl ?>" />
You can check other function for Varien_Image at
http://docs.magentocommerce.com/Varien/elementindex_Varien_Image.html
from: http://blog.chapagain.com.np/magento-resize-image/
发表评论
-
Magento: 后台显示图片不能找到 Image file was not found on product tab
2016-08-30 02:22 2879I was uploading some images f ... -
理解WordPress的PingBack和TrackBack
2016-08-26 02:21 5667pingback和trackback的功 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(四)
2016-06-07 11:40 981自上一篇之后,5天过去了,这篇文章总算是挤出来了... 其实 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(三)
2016-06-07 11:41 1999原则上WDCP安装好了,就可以直接使用了,FTP、MySQL ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(二)
2016-06-07 01:33 948上一篇讲到,主机正常运转了。但是此时如果直接访问公网IP是 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(一)
2016-06-07 01:31 21546现在小站唯一的流量都靠AWS这个关键词了,刚好要用AWS重新 ... -
零基础 Amazon Web Services (AWS) 入门教程 (列表)
2016-06-07 01:32 2032在 Amazon Web Services 上托 ... -
Magento 1.9:新订单通知 Admin Order Notifier
2016-06-02 02:48 798Here is a little Mag ... -
Magento 1.9.X 系列教程
2016-05-14 02:44 2243Magento安装下载教学: Magento教程 1 ... -
Magento: 产品页面下jquery change函数失效 Call javascript function onchange product option
2016-05-05 06:39 1693明显的原因是change函数跟magento默认的oncha ... -
Magento: 判断是否为手机浏览 Optimise Web's Mobile Detect Class for Magento
2016-04-29 07:01 1120项目地址:Optimise Web's Mobile Det ... -
Magento: Gird 和 form 区域 Module Development Series – Magento Admin Module
2016-04-28 02:39 632In this tutorial, we are goi ... -
Magento: addAttributeToFilter 和 addFieldToFilter 的区别 Difference between addAttri
2016-04-28 02:34 982addAttributeToFilter is use ... -
Magento: 后台获取menu链接 Getting the admin panel urls
2016-04-28 02:34 733The url for customer page in t ... -
Magento : 调用文件上传 upload file frontend
2016-04-27 01:25 1315bool mkdir ( string $pathname ... -
Magento: 自定义用户登录导向页面 Redirect Customer to Previous Page After Login
2016-04-26 02:45 1816Configuration Settings – L ... -
Magento: 代替flash上传 How to disable Flash uploader in Magento (product images and
2016-04-06 05:04 10831. 替换产品页flash上传按钮 - 使用 Du ... -
Magento: 在客户账户中添加自定义链接 My Account Add Link
2016-04-05 14:05 1194This extension add new link an ... -
Magento: 根据产品属性加载产品信息 Load A Category or Product by an Attribute
2016-03-26 01:35 894Load a Product by ID <?ph ... -
Magento模块开发之数据库SQL操作方法说明
2016-03-26 01:31 1288今天主要来看Magento中的Mysql4/Resource ...
相关推荐
Magento 图片延时加载插件,用来解决网站速度慢或者图片数量多的问题
magento批量处理订单的发货,关闭,填写物流单号等状态
magento 后台订单显示图片插件,可以让magento 后台订单显示图片,直接覆盖原文件即可!
Magento Beginner's Guide
magento处理不同的头部header
magento颜色属性图片展示插件,经过测试适用于magento1.7
magento后台显示订单图片,便于浏览订单
magento数据结构分析 magento数据字典
Magento 1.3 PHP Developer's Guide mangeto开发资料
MagentoBeginner's Guide.pdf [Packt]出品,最早的Magento精品书之一,原书地址:http://www.amazon.com/Magento-Beginners-Guide-William-Rice/dp/1847195946
magento的SMTP插件magento的SMTP插件magento的SMTP插件
NULL 博文链接:https://hudeyong926.iteye.com/blog/1416591
产品图像清洁器 [M2] ...composer config repositories.hs-module-image-clean vcs https://github.com/hungersoft/magento2-image-clean.git composer require hs/module-image-clean:dev-master php
magik shoes magento 模板, magento 1.7 模板
magento 颜色属性切换图片,兼容1.4-1.9,有说明文档,和安装截图
Magento 2 Beginners Guide by Gabriel Guarino English | 14 Mar. 2017 | ASIN: B01MS81BQX | 442 Pages | AZW3 | 31.84 MB Key Features Set up and manage your very first online store with a friendly and ...
magento2跨域处理包
Magento插件开发手册 Magento Extension Developers Guide
深入理解Magento 由精东博客下载下来制作成pdf
magento 评论插件