private function addThumbDefinition(UrlGenerator $generator)
 {
     if (isset($this->query['format'])) {
         $generator->format($this->query['format']);
     }
     if (isset($this->query['fill'])) {
         $generator->backgroundFill($this->query['fill']);
     }
     $parts = explode("/", $this->urlParts['thumbnailDefinition']);
     $mode = array_shift($parts);
     $generator->mode($mode);
     if ($mode == UrlGenerator::MODE_SCALE_TO_WIDTH || $mode == UrlGenerator::MODE_SCALE_TO_WIDTH_DOWN) {
         $generator->width(array_shift($parts));
         return;
     }
     foreach (array_chunk($parts, 2) as $chunk) {
         if (count($chunk) != 2) {
             $this->reportError('invalid chunk');
         }
         list($key, $val) = $chunk;
         switch ($key) {
             case 'width':
                 $generator->width($val);
                 break;
             case 'height':
                 $generator->height($val);
                 break;
             case 'x-offset':
                 $generator->xOffset($val);
                 break;
             case 'y-offset':
                 $generator->yOffset($val);
                 break;
             case 'window-width':
                 $generator->windowWidth($val);
                 break;
             case 'window-height':
                 $generator->windowHeight($val);
                 break;
             default:
                 $this->reportError('invalid key while building thumb mode', ['key' => $key, 'val' => $val]);
                 break;
         }
     }
 }
Esempio n. 2
0
 /**
  * apply a legacy thumb definition to a vignette url generator. ex: takes $legacyDefinition = /500px-someFilename.jpg
  * and applies ->scaleToWidth(500); to $generator;
  * @param UrlGenerator $generator
  * @param $legacyDefinition
  * @return UrlGenerator
  */
 public static function applyLegacyThumbDefinition(UrlGenerator $generator, $legacyDefinition)
 {
     $legacyDefinition = urldecode($legacyDefinition);
     if (preg_match('/^(\\d+)px-/', $legacyDefinition, $matches)) {
         $generator->scaleToWidth($matches[1]);
     } elseif (preg_match('/^(\\d+)x(\\d+)-/', $legacyDefinition, $matches)) {
         $generator->fixedAspectRatio()->width($matches[1])->height($matches[2]);
     } elseif (preg_match('/^(\\d+)x(\\d+)x(\\d+)-/', $legacyDefinition, $matches)) {
         $generator->zoomCrop()->width($matches[1])->height($matches[2]);
     }
     if (preg_match('/-(-{0,1}\\d+),(\\d+),(-{0,1}\\d+),(\\d+)-/', $legacyDefinition, $matches)) {
         if ($generator->getMode() == UrlGenerator::MODE_SCALE_TO_WIDTH || $generator->getMode() == UrlGenerator::MODE_SCALE_TO_WIDTH_DOWN) {
             $generator->windowCrop();
         } else {
             $generator->windowCropFixed();
         }
         $generator->xOffset($matches[1])->yOffset($matches[3])->windowWidth($matches[2] - $matches[1])->windowHeight($matches[4] - $matches[3]);
     }
     if (preg_match('/\\.([a-z]+)$/i', $legacyDefinition, $matches)) {
         $generator = self::setThumbnailFormat($generator, $matches[1]);
     }
     return $generator;
 }