/** * Create thumbnail for image and save it to thumbnails directory * * @param string $source Image path to be resized * @param bool $keepRation Keep aspect ratio or not * @return bool|string Resized filepath or false if errors were occurred */ public function resizeFile($source, $keepRation = true) { if (!$this->_filesystem->isFile($source) || !$this->_filesystem->isReadable($source)) { return false; } $targetDir = $this->getThumbsPath($source); if (!$this->_filesystem->isWritable($targetDir)) { $this->_filesystem->createDirectory($targetDir); } if (!$this->_filesystem->isWritable($targetDir)) { return false; } $adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType(); $image = Varien_Image_Adapter::factory($adapter); $image->open($source); $width = $this->getConfigData('resize_width'); $height = $this->getConfigData('resize_height'); $image->keepAspectRatio($keepRation); $image->resize($width, $height); $dest = $targetDir . DS . pathinfo($source, PATHINFO_BASENAME); $image->save($dest); if ($this->_filesystem->isFile($dest)) { return $dest; } return false; }
/** * Simple check if file is image * * @param array|string $fileInfo - either file data from Zend_File_Transfer or file path * @return boolean */ protected function _isImage($fileInfo) { // Maybe array with file info came in if (is_array($fileInfo)) { return strstr($fileInfo['type'], 'image/'); } // File path came in - check the physical file if (!$this->_filesystem->isReadable($fileInfo)) { return false; } $imageInfo = getimagesize($fileInfo); if (!$imageInfo) { return false; } return true; }
/** * Load local package data array * * @param string $packageName without extension * @return array|false */ public function loadLocalPackage($packageName) { //check LFI protection $this->checkLfiProtection($packageName); $path = $this->getLocalPackagesPath(); $xmlFile = $path . $packageName . '.xml'; $serFile = $path . $packageName . '.ser'; if ($this->_filesystem->isFile($xmlFile) && $this->_filesystem->isReadable($xmlFile)) { $xml = simplexml_load_string($this->_filesystem->read($xmlFile)); $data = Mage::helper('Mage_Core_Helper_Data')->xmlToAssoc($xml); if (!empty($data)) { return $data; } } if ($this->_filesystem->isFile($serFile) && $this->_filesystem->isReadable($xmlFile)) { $data = unserialize($this->_filesystem->read($serFile)); if (!empty($data)) { return $data; } } return false; }