/** * Transform an url or path for thumbor * * @param string $orig the original url or path * @param string $transformation the name of the transformation to apply to the original image * @param array $overrides an array of additionnal filters to override the ones from the transformation * * @return \Thumbor\Url\Builder * * @throws \Jb\Bundle\PhumborBundle\Transformer\Exception\UnknownTransformationException */ public function transform($orig, $transformation = null, $overrides = array()) { $url = $this->factory->url($orig); if (is_null($transformation) && count($overrides) == 0) { return $url; } // Check if a transformation is given without overrides if (!isset($this->transformations[$transformation]) && count($overrides) == 0) { throw new Exception\UnknownTransformationException("Unknown transformation {$transformation}. Use on of " . "the following " . implode(', ', array_keys($this->transformations))); } // Override transformation configuration with custom values $configuration = array(); if (isset($this->transformations[$transformation])) { $configuration = $this->transformations[$transformation]; } $configuration = array_merge($configuration, $overrides); // Build url from transformation configuration foreach ($configuration as $filter => $arguments) { $method = self::$filterMethod[$filter]; $this->{$method}($url, $arguments); } return $url; }
/** * Test filters */ public function testFilters() { $transformedUrl = $this->transformer->transform('http://phumbor.jb.fr/logo.png', null, array('filters' => array(array('name' => 'brightness', 'arguments' => 56), array('name' => 'color', 'arguments' => array('black', 'red'))))); $buildedUrl = $this->factory->url('http://phumbor.jb.fr/logo.png')->addFilter('brightness', 56)->addFilter('color', 'black', 'red'); $this->assertEquals($transformedUrl, $buildedUrl); }
/** * Test twig get filters */ public function testTransform() { $transformedUrl = $this->extension->transform('logo.png', 'width_50'); $builtUrl = $this->factory->url('logo.png')->resize(50, 0); $this->assertEquals($builtUrl, $transformedUrl); }