Ejemplo n.º 1
0
 public function drawText(Image $image, $string, $offsetY)
 {
     $box = new Box($image->getSize()->getWidth(), $image->getSize()->getHeight() / 4);
     $fitter = new Fitter($string, $this->getFont());
     $fitter->makeTextFitInBox($box);
     $boxes = $fitter->getTextBoxes();
     $start = $fitter->getStartingPointForCenteredBox($image->getSize(), $boxes[0]);
     foreach ($fitter->getLines() as $k => $line) {
         $start = $fitter->getStartingPointForCenteredBox($image->getSize(), $boxes[$k], $offsetY);
         $image->draw()->text($line, $fitter->getFont(), $start);
         if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
             $offsetY += $fitter->getFont()->getSize() * 96 / 72;
         } else {
             $offsetY += $fitter->getFont()->getSize();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Paste another image into this one a the specified dimension.
  *
  * @param ImageInterface $image   Image to paste.
  * @param int            $offsetX Offset on x axis.
  * @param int            $offsetY Offset on y axis
  *
  * @return $this
  */
 public function paste(ImageInterface $image, $offsetX = 0, $offsetY = 0)
 {
     $point = new Point($offsetX, $offsetY);
     $this->image->paste($image->getInstance(), $point);
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * generateThumbnail
  *
  * @param DocumentInterface $document
  * @param array             $dimension
  *
  * @return array|null|string
  */
 public function generateThumbnail(DocumentInterface $document, $dimension)
 {
     list($width, $height) = array_map('intval', explode('x', $dimension));
     $cacheFile = sprintf('%s/%s/%s/%s.png', $this->options['cache_path'], $dimension, $document->getNode()->getSlug(), $document->getSlug());
     if (!is_file($cacheFile)) {
         $size = new Box($width, $height);
         $mode = ImageInterface::THUMBNAIL_INSET;
         $absPath = $this->options['storage_path'] . DIRECTORY_SEPARATOR . (null !== $document->getThumbnail() ? $document->getThumbnail() : $document->getFilename());
         if (!is_file($absPath) || filesize($absPath) >= 100000000) {
             $cacheFile = $this->mimeTypeManager->getMimetypeImage($absPath, max([$width, $height]));
         } else {
             try {
                 if (pathinfo($absPath, PATHINFO_EXTENSION) === 'pdf') {
                     $absPath .= '[0]';
                 }
                 $imagick = new \Imagick($absPath);
                 $imagick->setCompression(Imagick::COMPRESSION_LZW);
                 $imagick->setResolution(72, 72);
                 $imagick->setCompressionQuality(90);
                 $image = new Image($imagick, new RGB(), new MetadataBag());
                 if (!is_dir(dirname($cacheFile))) {
                     mkdir(dirname($cacheFile), 0777, true);
                 }
                 $image->thumbnail($size, $mode)->save($cacheFile, array('quality' => 90));
             } catch (\Exception $e) {
                 $cacheFile = $this->mimeTypeManager->getMimetypeImage($this->options['storage_path'] . DIRECTORY_SEPARATOR . $document->getFilename(), max([$width, $height]));
             }
         }
     }
     return $cacheFile;
 }