コード例 #1
0
ファイル: ImageViewHelper.php プロジェクト: mcmz/focuspoint
 /**
  * Resize a given image (if required) and renders the respective img tag
  *
  * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
  *
  * @param string $src a path to a file, a combined FAL identifier or an uid (integer). If $treatIdAsReference is set, the integer is considered the uid of the sys_file_reference record. If you already got a FAL object, consider using the $image parameter instead
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer $minWidth minimum width of the image
  * @param integer $minHeight minimum height of the image
  * @param integer $maxWidth maximum width of the image
  * @param integer $maxHeight maximum height of the image
  * @param boolean $treatIdAsReference given src argument is a sys_file_reference record
  * @param FileInterface|AbstractFileFolder $image a FAL object
  * @param string $ratio
  * @param bool $realCrop
  *
  * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
  * @return string Rendered tag
  */
 public function render($src = null, $width = null, $height = null, $minWidth = null, $minHeight = null, $maxWidth = null, $maxHeight = null, $treatIdAsReference = false, $image = null, $ratio = '1:1', $realCrop = true)
 {
     /** @var \HDNET\Focuspoint\Service\FocusCropService $service */
     $service = GeneralUtility::makeInstance('HDNET\\Focuspoint\\Service\\FocusCropService');
     try {
         $internalImage = $service->getViewHelperImage($src, $image, $treatIdAsReference);
         if ($realCrop) {
             $src = $service->getCroppedImageSrcByFile($internalImage, $ratio);
             $treatIdAsReference = false;
             $image = null;
         }
     } catch (\Exception $ex) {
         $realCrop = true;
     }
     try {
         parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight, $treatIdAsReference, $image);
     } catch (\Exception $ex) {
         return 'Missing image!';
     }
     if ($realCrop) {
         return $this->tag->render();
     }
     // Ratio calculation
     $focusPointY = $internalImage->getProperty('focus_point_y');
     $focusPointX = $internalImage->getProperty('focus_point_x');
     $focusTag = '<div class="focuspoint" data-image-imageSrc="' . $this->tag->getAttribute('src') . '" data-focus-x="' . $focusPointX / 100 . '" data-focus-y="' . $focusPointY / 100 . '" data-image-w="' . $this->tag->getAttribute('width') . '" data-image-h="' . $this->tag->getAttribute('height') . '">';
     return $focusTag . $this->tag->render() . '</div>';
 }
コード例 #2
0
 /**
  * The first three arguments are used for rendering the QR code.
  * All other arguments of the ImageViewHelper can be used, too.
  * But in this case the rendered QR code will scaled and the result will be blurred.
  *
  * @param string $data
  * @param integer $size size of the qrcode dots [px]
  * @param integer $margin margin of the qrcode [qrdots]
  * @param string $color
  * @param string $background
  *
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer $minWidth minimum width of the image
  * @param integer $minHeight minimum height of the image
  * @param integer $maxWidth maximum width of the image
  * @param integer $maxHeight maximum height of the image
  *
  * @return string rendered tag.
  */
 public function render($data = NULL, $size = NULL, $margin = NULL, $color = '000000', $background = 'FFFFFF', $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL)
 {
     if (is_null($data)) {
         $data = $this->renderChildren();
     }
     $src = $this->getImagePath($data, $size, $margin, $color, $background);
     return parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
 }
コード例 #3
0
 /**
  * Resizes a given image (if required) and renders the respective img tag
  *
  * @param string $src
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer $minWidth minimum width of the image
  * @param integer $minHeight minimum height of the image
  * @param integer $maxWidth maximum width of the image
  * @param integer $maxHeight maximum height of the image
  * @return string rendered tag.
  */
 public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL)
 {
     $image = '';
     try {
         $image = parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
     } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
     }
     return $image;
 }
コード例 #4
0
 /**
  * Resizes a given image (if required) and renders the respective img tag
  *
  * @param string $src
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param int $minWidth minimum width of the image
  * @param int $minHeight minimum height of the image
  * @param int $maxWidth maximum width of the image
  * @param int $maxHeight maximum height of the image
  * @param string $fallbackImage an optional fallback image if the $src image cannot be loaded
  * @return string rendered tag.
  */
 public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $fallbackImage = '')
 {
     $image = '';
     try {
         $image = parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
     } catch (\Exception $e) {
         if ($fallbackImage !== '') {
             $image = static::render($fallbackImage, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
         }
         /** @var \TYPO3\CMS\Core\Log\Logger $logger */
         $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
         $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
     }
     return $image;
 }
コード例 #5
0
 /**
  *
  * Renders the avatar.
  *
  * @param \Mittwald\Typo3Forum\Domain\Model\User\FrontendUser $user
  *                                                               The user whose avatar is to be rendered.
  * @param integer                                   $width      The desired avatar width
  * @param integer                                   $height     The desired avatar height
  * @return string              HTML content
  *
  */
 public function render(\Mittwald\Typo3Forum\Domain\Model\User\FrontendUser $user = NULL, $width = NULL, $height = NULL)
 {
     // if user ist not set
     $avatarFilename = NULL;
     if ($user != NULL) {
         $avatarFilename = $user->getImagePath();
     }
     if ($avatarFilename === NULL) {
         $avatarFilename = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('typo3_forum') . 'Resources/Public/Images/Icons/AvatarEmpty.png';
     }
     if ($height === NULL) {
         $height = $width;
     }
     return parent::render($avatarFilename, $width, $height);
 }
コード例 #6
0
 /**
  * Resizes a given image (if required) and renders the respective img tag
  *
  * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
  *
  * @param integer $fileUid
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer $minWidth minimum width of the image
  * @param integer $minHeight minimum height of the image
  * @param integer $maxWidth maximum width of the image
  * @param integer $maxHeight maximum height of the image
  * @param boolean $treatIdAsReference given src argument is a sys_file_reference record
  * @param boolean $urlOnly Just return the URL of the file
  *
  * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
  * @return string rendered tag.
  */
 public function render($fileUid = NULL, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $treatIdAsReference = FALSE, $urlOnly = FALSE)
 {
     $out = '';
     $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
     $file = $fileRepository->findByUid($fileUid);
     try {
         if ($file) {
             $out = parent::render($file->getCombinedIdentifier(), $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight, $treatIdAsReference);
         }
         if ($urlOnly && preg_match('/src="([^"]*)"/', $out, $matches)) {
             $out = $matches[1];
         }
     } catch (\Exception $e) {
         $out = null;
     }
     return $out;
 }
コード例 #7
0
 /**
  * Resize a given image (if required) and renders the respective img tag
  *
  * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
  *
  * @param string                           $src                a path to a file, a combined FAL identifier or an uid (integer). If $treatIdAsReference is set, the integer is considered the uid of the sys_file_reference record. If you already got a FAL object, consider using the $image parameter instead
  * @param string                           $width              width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string                           $height             height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer                          $minWidth           minimum width of the image
  * @param integer                          $minHeight          minimum height of the image
  * @param integer                          $maxWidth           maximum width of the image
  * @param integer                          $maxHeight          maximum height of the image
  * @param boolean                          $treatIdAsReference given src argument is a sys_file_reference record
  * @param FileInterface|AbstractFileFolder $image              a FAL object
  * @param string                           $ratio
  * @param bool                             $realCrop
  *
  * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
  * @return string Rendered tag
  */
 public function render($src = NULL, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $treatIdAsReference = FALSE, $image = NULL, $ratio = '1:1', $realCrop = FALSE)
 {
     $internalImage = $this->getImage($src, $treatIdAsReference);
     if ($realCrop) {
         /** @var \HDNET\Focuspoint\Service\FocusCropService $service */
         $service = GeneralUtility::makeInstance('HDNET\\Focuspoint\\Service\\FocusCropService');
         $src = $service->getCroppedImageSrcByFile($internalImage, $ratio);
         $treatIdAsReference = FALSE;
         $image = NULL;
     }
     parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight, $treatIdAsReference, $image);
     if ($realCrop) {
         return $this->tag->render();
     }
     // Ratio calculation
     $focusPointY = $internalImage->getProperty('focus_point_y');
     $focusPointX = $internalImage->getProperty('focus_point_x');
     $focusTag = '<div class="focuspoint" data-image-imageSrc="' . $this->tag->getAttribute('src') . '" data-focus-x="' . $focusPointX / 100 . '" data-focus-y="' . $focusPointY / 100 . '" data-image-w="' . $this->tag->getAttribute('width') . '" data-image-h="' . $this->tag->getAttribute('height') . '">';
     return $focusTag . $this->tag->render() . '</div>';
 }
コード例 #8
0
 /**
  * Resizes a given image (if required) and renders the respective img tag
  *
  * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
  * @param string $src
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer $minWidth minimum width of the image
  * @param integer $minHeight minimum height of the image
  * @param integer $maxWidth maximum width of the image
  * @param integer $maxHeight maximum height of the image
  * @return string rendered tag.
  */
 public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL)
 {
     $src = \TYPO3\CMS\Backend\Utility\IconUtility::skinImg('../typo3/', $src, '', 1);
     return parent::render('' . $src, $width, $height . $minWidth, $minHeight, $maxWidth, $maxHeight);
 }
コード例 #9
0
 /**
  * Initialize arguments.
  *
  * @return void
  */
 public function initializeArguments()
 {
     parent::initializeArguments();
     $this->registerTagAttribute('data-original', 'string', 'Original image for lazy loading', false);
 }