本文主要是介绍magento----设置图片背景颜色(按数值设定后缺的部分用背景色填充),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.
magento图片的底层处理是在:/lib/Varien/Image/Adapter/Abstract.php
函数: public function backgroundColor($value = null)
/**
* Get/set keepBackgroundColor
*
* @param array $value
* @return array
*/
public function backgroundColor($value = null)
{
if (null !== $value) {
if ((!is_array($value)) || (3 !== count($value))) {
return;
}
foreach ($value as $color) {
if ((!is_integer($color)) || ($color < 0) || ($color > 255)) {
return;
}
}
}
$this->_backgroundColor = $value;
return $this->_backgroundColor;
}
1.1注意: $this->_backgroundColor = $value;$value为rgb的颜色格式。
1.2
格式在线转换hex-->rgb
http://www.yellowpipe.com/yis/tools/hex-to-rgb/color-converter.php
/lib/Varien/Image/Adapter/abstract.php
1.3可以在这里直接更改$this->_backgroundColor,将所有的图片设置成一个颜色。
1.4
如果不同的图片对应的背景色不一样,那么需要在程序里面设置,如:
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(160, 190)->backgroundColor(248,248,248); ?>
,这里可以设置该图片的背景色,仅仅这一组。
这篇关于magento----设置图片背景颜色(按数值设定后缺的部分用背景色填充)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!