/**
  * @param PhpGdEvent $event
  */
 public function addImageExtras(PhpGdEvent $event)
 {
     if ($this->extras) {
         $image = $event->getImage();
         $image->addExtras($this->extras);
     }
 }
 /**
  * @param  PhpGdEvent $event
  * @throws InvalidArgumentException
  */
 public function verifySavedFormat(PhpGdEvent $event)
 {
     $format = $event->getOptions()['output_format'];
     if ('default' !== $format && !$this->context->isImageFormatSupported($format)) {
         throw new InvalidArgumentException('output.image.format.not.supported.%cp_unsupported%', ['%cp_unsupported%' => '"' . $format . '"']);
     }
 }
 /**
  * param PhpGdEvent $event
  */
 public function addImageExtras(PhpGdEvent $event)
 {
     $image = $event->getImage();
     if (array_key_exists('gif_error', $image->getExtras())) {
         return;
     }
     $image->addExtras($this->extras);
 }
Ejemplo n.º 4
0
 /**
  * @param PhpGdEvent $event
  */
 public function createImage(PhpGdEvent $event)
 {
     $layers = $event->getLayers();
     if (1 === count($layers) && $layers[0]->get('image.width') === $layers[0]->get('final.width') && $layers[0]->get('image.height') === $layers[0]->get('final.height') && $layers[0]->get('image.format') === $layers[0]->get('final.format')) {
         $options = $event->getOptions();
         $image = $this->factory->createImage($layers, $options);
         $event->setImage($image);
         $event->stopPropagation();
     }
 }
 /**
  * @param PhpGdEvent
  */
 public function initFinalFormat(PhpGdEvent $event)
 {
     $layer = $event->getLayers()[0];
     $options = $event->getOptions();
     if ('default' === $options['output_format']) {
         $format = $layer->get('image.format');
     } else {
         $format = $options['output_format'];
     }
     $layer->set('final.format', $format);
 }
Ejemplo n.º 6
0
 /**
  * @param PhpGdEvent $event
  */
 public function addImageMetadatas(PhpGdEvent $event)
 {
     $image = $event->getImage();
     $layers = $event->getLayers();
     $format = $layers[0]->get('final.format');
     $image->setMime($this->context->getImageMime($format));
     $image->setExtension($this->context->getImageExtension($format));
     $image->setWidth($layers[0]->get('final.width'));
     $image->setHeight($layers[0]->get('final.height'));
     $image->addExtras(['original_width' => $layers[0]->get('image.width'), 'original_height' => $layers[0]->get('image.height')]);
 }
Ejemplo n.º 7
0
 /**
  * @param  PhpGdEvent
  * @throws RuntimeException
  */
 public function verifyFreeType(PhpGdEvent $event)
 {
     $layers = $event->getLayers();
     foreach ($layers as $key => $layer) {
         if (!$layer instanceof TextLayerInterface) {
             continue;
         }
         if (!$this->context->isFreeTypeSupported()) {
             throw new RuntimeException('adding.text.not.supported');
         }
         break;
     }
 }
Ejemplo n.º 8
0
 /**
  * @inheritDoc
  */
 public function getImage(array $layers, array $options)
 {
     $dispatcher = new EventDispatcher();
     $extension = new DelegatingExtension();
     $extension->boot($dispatcher);
     $event = new PhpGdEvent($layers, $options);
     $dispatcher->dispatch(PhpGdEvents::PRE_IMAGE, $event);
     if (!$event->getImage()) {
         $event = new PhpGdEvent($layers, $options);
         $dispatcher->dispatch(PhpGdEvents::IMAGE, $event);
     }
     $image = $event->getImage();
     $event = new PhpGdEvent($layers, $options);
     $event->setImage($image);
     $dispatcher->dispatch(PhpGdEvents::FINISH_IMAGE, $event);
     return $event->getImage();
 }
 /**
  * @param PhpGdEvent $event
  */
 public function createImage(PhpGdEvent $event)
 {
     $image = $this->factory->createImage($event->getLayers(), $event->getOptions());
     $event->setImage($image);
     $event->stopPropagation();
 }
 /**
  * @param PhpGdEvent
  */
 public function termImcUri(PhpGdEvent $event)
 {
     $layers = $event->getLayers();
     foreach ($layers as $key => $layer) {
         if (!$layer instanceof ImageAwareLayerInterface) {
             continue;
         }
         if ($layer->has('image.imc_uri')) {
             ImcStream::fclose($layer->get('image.imc_uri'));
             $layer->remove('image.imc_uri');
         }
     }
 }