Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function process(Configuration $config)
 {
     $sprite = $config->getImagine()->create(new Box(ceil($config->getWidth() * iterator_count($config->getFinder())), 1), $config->getColor());
     $pointer = 0;
     $styles = '';
     foreach ($config->getFinder() as $file) {
         $image = $config->getImagine()->open($file->getRealPath());
         // resize if image exceeds fixed with
         if (true === $this->getOption('resize') && $image->getSize()->getWidth() > $config->getWidth()) {
             $image->resize(new Box($config->getWidth(), round($image->getSize()->getHeight() / $image->getSize()->getWidth() * $config->getWidth())));
         }
         // adjust height if necessary
         if ($image->getSize()->getHeight() > $sprite->getSize()->getHeight()) {
             // copy&paste into an extended sprite
             $sprite = $config->getImagine()->create(new Box($sprite->getSize()->getWidth(), $image->getSize()->getHeight()), $config->getColor())->paste($sprite, new Point(0, 0));
         }
         // paste image into sprite
         $sprite->paste($image, new Point($pointer, 0));
         // append stylesheet code
         $styles .= $this->parseSelector($config->getSelector(), $file, $pointer);
         // move horizontal cursor
         $pointer += $config->getWidth();
     }
     $this->save($config, $sprite, $styles);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function process(Configuration $config)
 {
     $sprite = $config->getImagine()->create(new Box(1, 1), $config->getColor());
     $pointer = 0;
     $styles = '';
     foreach ($config->getFinder() as $file) {
         $image = $config->getImagine()->open($file->getRealPath());
         // adjust height if necessary
         $height = $sprite->getSize()->getHeight();
         if ($image->getSize()->getHeight() > $height) {
             $height = $image->getSize()->getHeight();
         }
         // copy&paste into an extended sprite
         $sprite = $config->getImagine()->create(new Box($sprite->getSize()->getWidth() + $image->getSize()->getWidth(), $height), $config->getColor())->paste($sprite, new Point(0, 0));
         // paste image into sprite
         $sprite->paste($image, new Point($pointer, 0));
         // append stylesheet code
         $styles .= $this->parseSelector($config->getSelector(), $file, $pointer);
         // move horizontal cursor
         $pointer += $image->getSize()->getWidth();
     }
     $this->save($config, $sprite, $styles);
 }