Skip to content

Commit

Permalink
Performance improvement (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab authored Apr 30, 2021
1 parent 8496673 commit 46ebf30
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/code/core/Mage/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class Mage_Catalog_Model_Product_Image extends Mage_Core_Model_Abstract
*
* @var array
*/
protected $_backgroundColor = array(255, 255, 255);
protected $_backgroundColor = array(255, 255, 255);
protected $_backgroundColorStr = 'ffffff';

/**
* Absolute path to and original (full resolution) image
Expand Down Expand Up @@ -108,6 +109,11 @@ class Mage_Catalog_Model_Product_Image extends Mage_Core_Model_Abstract
protected $_watermarkHeigth;
protected $_watermarkImageOpacity = 70;

/**
* @var string directory
*/
protected static $_baseMediaPath;

/**
* @param int $width
* @return $this
Expand Down Expand Up @@ -213,6 +219,7 @@ public function setConstrainOnly($flag)
public function setBackgroundColor(array $rgbArray)
{
$this->_backgroundColor = $rgbArray;
$this->_backgroundColorStr = $this->_rgbToString($rgbArray);
return $this;
}

Expand Down Expand Up @@ -347,7 +354,11 @@ public function setBaseFile($file)
if (($file) && (0 !== strpos($file, '/', 0))) {
$file = '/' . $file;
}
$baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();

if (empty(self::$_baseMediaPath)) {
self::$_baseMediaPath = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();
}
$baseDir = self::$_baseMediaPath;

if ('/no_selection' == $file) {
$file = null;
Expand Down Expand Up @@ -390,7 +401,7 @@ public function setBaseFile($file)

// build new filename (most important params)
$path = array(
Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
self::$_baseMediaPath,
'cache',
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir()
Expand All @@ -405,7 +416,7 @@ public function setBaseFile($file)
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
$this->_backgroundColorStr,
'angle' . $this->_angle,
'quality' . $this->_quality
);
Expand Down

0 comments on commit 46ebf30

Please sign in to comment.