global variable $thumbnailUrlFactory = Thumbor\Url\BuilderFactory::construct( 'http://thumbor.example.com', 'secret' ); elsewhere in your app echo $thumbnailUrlFactory ->urlFrom('http://example.com/llamas.jpg') ->fitIn(320, 240) etc ;
コード例 #1
0
 public function testUrl()
 {
     $server = 'http://thumbor.example.com';
     $secret = 'butts';
     $original = 'http://example.com/llamas.jpg';
     $builder = BuilderFactory::construct($server, $secret)->url($original);
     $expected = Builder::construct($server, $secret, $original);
     $this->assertEquals($expected, $builder);
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app['phumbor'] = $this->app->share(function ($app) {
         return \Thumbor\Url\BuilderFactory::construct(Config::get('laravel-phumbor::server'), Config::get('laravel-phumbor::key'));
     });
 }
コード例 #5
0
 /**
  * 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);
 }