/** * Get thumbnail path * * @param string $type * @param Replica_ImageProxy_Abstract $proxy * @return null|string - Relative path to thumbnail */ function thumbnail_path($type, Replica_ImageProxy_Abstract $proxy) { $config = sfReplicaThumbnail::getConfig($type); // Has image if ($proxy->getUid()) { sfReplicaThumbnail::loadMacro($type, $config['macro']); // If image not found return null try { $proxy->setMimeType($config['mimetype']); if (null !== $config['quality']) { $proxy->setQuality($config['quality']); } return sfConfig::get('app_thumbnail_dir') . '/' . Replica::cache()->get($type, $proxy); } catch (Replica_Exception_ImageNotInitialized $e) { if ($config['required']) { throw $e; } return; } // Default image } else { if (isset($config['default'])) { return $config['default']; } } }
/** * Возвращает путь к превьюшке * * @param string $type * @return string */ public function getImagePath($type) { if ($this->isNew() || !$this->size) { $proxy = new Replica_ImageProxy_FromFile(null); } else { $proxy = new sfReplicaImageDoctrine($this); } $config = sfReplicaThumbnail::getConfig($type); // Has image if ($proxy->getUid()) { sfReplicaThumbnail::loadMacro($type, $config['macro']); // If image not found return null try { $path = sfConfig::get('app_thumbnail_dir') . '/' . Replica::cache()->get($type, $proxy, $config['mimetype']); } catch (Replica_Exception_ImageNotInitialized $e) { return; } // Default image } else { if (isset($config['default'])) { $path = $config['default']; } } return $path; }
/** * Load macro once */ public function testLoadMacroOnce() { // first $config = array('Replica_Macro_Null' => array()); sfReplicaThumbnail::loadMacro('load_once', $config); // second $config = array('Replica_Macro_ThumbnailFit' => array($width = 10, $height = 20)); sfReplicaThumbnail::loadMacro('load_once', $config); $this->assertTrue(Replica::hasMacro('load_once'), 'Macro is initialized'); $this->assertType('Replica_Macro_Chain', $macro = Replica::getMacro('load_once')); $this->assertEquals(array('Replica_Macro_Null' => array()), $macro->getParameters()); }