Definition at line 34 of file Image.php.
_checkMemory | ( | $ | file = null |
) | [protected] |
Definition at line 146 of file Image.php.
00147 { 00148 // print '$this->_getMemoryLimit() = '.$this->_getMemoryLimit(); 00149 // print '$this->_getMemoryUsage() = '.$this->_getMemoryUsage(); 00150 // print '$this->_getNeedMemoryForBaseFile() = '.$this->_getNeedMemoryForBaseFile(); 00151 00152 return $this->_getMemoryLimit() > ($this->_getMemoryUsage() + $this->_getNeedMemoryForFile($file)); 00153 }
_getMemoryLimit | ( | ) | [protected] |
Definition at line 155 of file Image.php.
00156 { 00157 $memoryLimit = ini_get('memory_limit'); 00158 00159 if (!isSet($memoryLimit[0])){ 00160 $memoryLimit = "128M"; 00161 } 00162 00163 if (substr($memoryLimit, -1) == 'M') { 00164 return (int)$memoryLimit * 1024 * 1024; 00165 } 00166 return $memoryLimit; 00167 }
_getMemoryUsage | ( | ) | [protected] |
_getNeedMemoryForFile | ( | $ | file = null |
) | [protected] |
Definition at line 177 of file Image.php.
00178 { 00179 $file = is_null($file) ? $this->getBaseFile() : $file; 00180 if (!$file) { 00181 return 0; 00182 } 00183 00184 if (!file_exists($file) || !is_file($file)) { 00185 return 0; 00186 } 00187 00188 $imageInfo = getimagesize($file); 00189 00190 if (!isset($imageInfo['channels'])) { 00191 // if there is no info about this parameter lets set it for maximum 00192 $imageInfo['channels'] = 4; 00193 } 00194 if (!isset($imageInfo['bits'])) { 00195 // if there is no info about this parameter lets set it for maximum 00196 $imageInfo['bits'] = 8; 00197 } 00198 return round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65); 00199 }
clearCache | ( | ) |
Definition at line 511 of file Image.php.
00512 { 00513 $directory = Mage::getBaseDir('media') . DS.'catalog'.DS.'product'.DS.'cache'.DS; 00514 $io = new Varien_Io_File(); 00515 $io->rmdir($directory, true); 00516 }
getBaseFile | ( | ) |
getDestinationSubdir | ( | ) |
getImageProcessor | ( | ) |
Definition at line 318 of file Image.php.
00319 { 00320 if( !$this->_processor ) { 00321 // var_dump($this->_checkMemory()); 00322 // if (!$this->_checkMemory()) { 00323 // $this->_baseFile = null; 00324 // } 00325 $this->_processor = new Varien_Image($this->getBaseFile()); 00326 } 00327 $this->_processor->keepAspectRatio($this->_keepAspectRatio); 00328 $this->_processor->keepFrame($this->_keepFrame); 00329 $this->_processor->keepTransparency($this->_keepTransparency); 00330 $this->_processor->constrainOnly($this->_constrainOnly); 00331 $this->_processor->backgroundColor($this->_backgroundColor); 00332 return $this->_processor; 00333 }
getNewFile | ( | ) |
getUrl | ( | ) |
Definition at line 423 of file Image.php.
00424 { 00425 $baseDir = Mage::getBaseDir('media'); 00426 $path = str_replace($baseDir . DS, "", $this->_newFile); 00427 return Mage::getBaseUrl('media') . str_replace(DS, '/', $path); 00428 }
getWatermarkHeigth | ( | ) |
getWatermarkPosition | ( | ) |
getWatermarkWidth | ( | ) |
isCached | ( | ) |
push | ( | ) |
Definition at line 430 of file Image.php.
00431 { 00432 $this->getImageProcessor()->display(); 00433 }
resize | ( | ) |
Definition at line 339 of file Image.php.
00340 { 00341 if (is_null($this->getWidth()) && is_null($this->getHeight())) { 00342 return $this; 00343 } 00344 $this->getImageProcessor()->resize($this->_width, $this->_height); 00345 return $this; 00346 }
rotate | ( | $ | angle | ) |
Definition at line 351 of file Image.php.
00352 { 00353 $angle = intval($angle); 00354 $this->getImageProcessor()->rotate($angle); 00355 return $this; 00356 }
saveFile | ( | ) |
Definition at line 414 of file Image.php.
00415 { 00416 $this->getImageProcessor()->save($this->getNewFile()); 00417 return $this; 00418 }
setAngle | ( | $ | angle | ) |
Set angle for rotating
This func actually affects only the cache filename.
int | $angle |
Definition at line 366 of file Image.php.
setBackgroundColor | ( | array $ | rgbArray | ) |
setBaseFile | ( | $ | file | ) |
Set filenames for base file and new file
string | $file |
Definition at line 227 of file Image.php.
00228 { 00229 if (($file) && (0 !== strpos($file, '/', 0))) { 00230 $file = '/' . $file; 00231 } 00232 $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(); 00233 00234 if ('/no_selection' == $file) { 00235 $file = null; 00236 } 00237 if ($file) { 00238 if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) { 00239 $file = null; 00240 } 00241 } 00242 if (!$file) { 00243 // check if placeholder defined in config 00244 $isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder"); 00245 $configPlaceholder = '/placeholder/' . $isConfigPlaceholder; 00246 if ($isConfigPlaceholder && file_exists($baseDir . $configPlaceholder)) { 00247 $file = $configPlaceholder; 00248 } 00249 else { 00250 // replace file with skin or default skin placeholder 00251 $skinBaseDir = Mage::getDesign()->getSkinBaseDir(); 00252 $skinPlaceholder = "/images/catalog/product/placeholder/{$this->getDestinationSubdir()}.jpg"; 00253 $file = $skinPlaceholder; 00254 if (file_exists($skinBaseDir . $file)) { 00255 $baseDir = $skinBaseDir; 00256 } 00257 else { 00258 $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default')); 00259 } 00260 } 00261 } 00262 00263 $baseFile = $baseDir . $file; 00264 00265 if ((!$file) || (!file_exists($baseFile))) { 00266 throw new Exception(Mage::helper('catalog')->__('Image file not found')); 00267 } 00268 $this->_baseFile = $baseFile; 00269 00270 // build new filename (most important params) 00271 $path = array( 00272 Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), 00273 'cache', 00274 Mage::app()->getStore()->getId(), 00275 $path[] = $this->getDestinationSubdir() 00276 ); 00277 if((!empty($this->_width)) || (!empty($this->_height))) 00278 $path[] = "{$this->_width}x{$this->_height}"; 00279 // add misc params as a hash 00280 $path[] = md5( 00281 implode('_', array( 00282 ($this->_keepAspectRatio ? '' : 'non') . 'proportional', 00283 ($this->_keepFrame ? '' : 'no') . 'frame', 00284 ($this->_keepTransparency ? '' : 'no') . 'transparency', 00285 ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly', 00286 $this->_rgbToString($this->_backgroundColor), 00287 'angle' . $this->_angle 00288 )) 00289 ); 00290 // append prepared filename 00291 $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash 00292 00293 return $this; 00294 }
setConstrainOnly | ( | $ | flag | ) |
setDestinationSubdir | ( | $ | dir | ) |
setHeight | ( | $ | height | ) |
setImageProcessor | ( | $ | processor | ) |
setKeepAspectRatio | ( | $ | keep | ) |
setKeepFrame | ( | $ | keep | ) |
setKeepTransparency | ( | $ | keep | ) |
setSize | ( | $ | size | ) |
Definition at line 130 of file Image.php.
00131 { 00132 // determine width and height from string 00133 list($width, $height) = explode('x', strtolower($size), 2); 00134 foreach (array('width', 'height') as $wh) { 00135 $$wh = (int)$$wh; 00136 if (empty($$wh)) 00137 $$wh = null; 00138 } 00139 00140 // set sizes 00141 $this->setWidth($width)->setHeight($height); 00142 00143 return $this; 00144 }
setWatermark | ( | $ | file, | |
$ | position = null , |
|||
$ | size = null , |
|||
$ | width = null , |
|||
$ | heigth = null | |||
) |
Definition at line 375 of file Image.php.
00376 { 00377 $filename = false; 00378 00379 if( !$file ) { 00380 return $this; 00381 } 00382 00383 $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(); 00384 00385 if( file_exists($baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file) ) { 00386 $filename = $baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file; 00387 } elseif ( file_exists($baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file) ) { 00388 $filename = $baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file; 00389 } elseif ( file_exists($baseDir . '/watermark/default/' . $file) ) { 00390 $filename = $baseDir . '/watermark/default/' . $file; 00391 } elseif ( file_exists($baseDir . '/watermark/' . $file) ) { 00392 $filename = $baseDir . '/watermark/' . $file; 00393 } else { 00394 $baseDir = Mage::getDesign()->getSkinBaseDir(); 00395 if( file_exists($baseDir . $file) ) { 00396 $filename = $baseDir . $file; 00397 } 00398 } 00399 00400 if( $filename ) { 00401 $this->getImageProcessor() 00402 ->setWatermarkPosition( ($position) ? $position : $this->getWatermarkPosition() ) 00403 ->setWatermarkWidth( ($width) ? $width : $this->getWatermarkWidth() ) 00404 ->setWatermarkHeigth( ($heigth) ? $heigth : $this->getWatermarkHeigth() ) 00405 ->watermark($filename); 00406 } 00407 00408 return $this; 00409 }
setWatermarkHeigth | ( | $ | heigth | ) |
setWatermarkPosition | ( | $ | position | ) |
setWatermarkSize | ( | $ | size | ) |
Definition at line 474 of file Image.php.
00475 { 00476 if( is_array($size) ) { 00477 $this->setWatermarkWidth($size['width']) 00478 ->setWatermarkHeigth($size['heigth']); 00479 } 00480 return $this; 00481 }
setWatermarkWidth | ( | $ | width | ) |
setWidth | ( | $ | width | ) |