/**
  * Get the cropped image by File Object
  *
  * @param FileInterface $file
  * @param string        $ratio
  *
  * @return string The new filename
  */
 public function getCroppedImageSrcByFile(FileInterface $file, $ratio)
 {
     $absoluteImageName = GeneralUtility::getFileAbsFileName($file->getPublicUrl());
     $focusPointX = MathUtility::forceIntegerInRange((int) $file->getProperty('focus_point_x'), -100, 100, 0);
     $focusPointY = MathUtility::forceIntegerInRange((int) $file->getProperty('focus_point_y'), -100, 100, 0);
     $tempImageFolder = 'typo3temp/focuscrop/';
     $tempImageName = $tempImageFolder . $file->getSha1() . '-' . str_replace(':', '-', $ratio) . '-' . $focusPointX . '-' . $focusPointY . '.' . $file->getExtension();
     $absoluteTempImageName = GeneralUtility::getFileAbsFileName($tempImageName);
     if (is_file($absoluteTempImageName)) {
         return $tempImageName;
     }
     $absoluteTempImageFolder = GeneralUtility::getFileAbsFileName($tempImageFolder);
     if (!is_dir($absoluteTempImageFolder)) {
         GeneralUtility::mkdir_deep($absoluteTempImageFolder);
     }
     $this->graphicalFunctions = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
     $imageSizeInformation = getimagesize($absoluteImageName);
     $width = $imageSizeInformation[0];
     $height = $imageSizeInformation[1];
     // dimensions
     /** @var \HDNET\Focuspoint\Service\DimensionService $service */
     $dimensionService = GeneralUtility::makeInstance('HDNET\\Focuspoint\\Service\\DimensionService');
     list($focusWidth, $focusHeight) = $dimensionService->getFocusWidthAndHeight($width, $height, $ratio);
     $cropMode = $dimensionService->getCropMode($width, $height, $ratio);
     list($sourceX, $sourceY) = $dimensionService->calculateSourcePosition($cropMode, $width, $height, $focusWidth, $focusHeight, $focusPointX, $focusPointY);
     // generate image
     $sourceImage = $this->graphicalFunctions->imageCreateFromFile($absoluteImageName);
     $destinationImage = imagecreatetruecolor($focusWidth, $focusHeight);
     $this->graphicalFunctions->imagecopyresized($destinationImage, $sourceImage, 0, 0, $sourceX, $sourceY, $focusWidth, $focusHeight, $focusWidth, $focusHeight);
     $this->graphicalFunctions->ImageWrite($destinationImage, $absoluteTempImageName, $GLOBALS['TYPO3_CONF_VARS']['GFX']['jpg_quality']);
     return $tempImageName;
 }
Exemple #2
0
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image)
 {
     if ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = '../';
     }
     return $uriPrefix . $image->getPublicUrl();
 }
Exemple #3
0
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image)
 {
     $imageUrl = $image->getPublicUrl();
     // no prefix in case of an already fully qualified URL (having a schema)
     if (strpos($imageUrl, '://')) {
         $uriPrefix = '';
     } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = '../';
     }
     return $uriPrefix . $imageUrl;
 }
 /**
  * Render for given File(Reference) HTML output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options controls = TRUE/FALSE (default TRUE), autoplay = TRUE/FALSE (default FALSE), loop = TRUE/FALSE (default FALSE)
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = array(), $usedPathsRelativeToCurrentScript = FALSE)
 {
     $additionalAttributes = array();
     if (!isset($options['controls']) || !empty($options['controls'])) {
         $additionalAttributes[] = 'controls';
     }
     if (!empty($options['autoplay'])) {
         $additionalAttributes[] = 'autoplay';
     }
     if (!empty($options['loop'])) {
         $additionalAttributes[] = 'loop';
     }
     return sprintf('<video width="%d" height="%d"%s><source src="%s" type="%s"></video>', (int) $width, (int) $height, empty($additionalAttributes) ? '' : ' ' . implode(' ', $additionalAttributes), htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)), $file->getMimeType());
 }
Exemple #5
0
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image)
 {
     $imageUrl = $image->getPublicUrl();
     // no prefix in case of an already fully qualified URL (having a schema)
     // We need to fix the dection for PHP 5.4.6 and below as the host detection is broken
     if (parse_url($imageUrl, PHP_URL_HOST) !== NULL || strpos($imageUrl, '//') === 0) {
         $uriPrefix = '';
     } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
     }
     return $uriPrefix . $imageUrl;
 }
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @param bool|FALSE $absolute Force absolute URL
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image, $absolute = false)
 {
     $imageUrl = $image->getPublicUrl();
     $parsedUrl = parse_url($imageUrl);
     // no prefix in case of an already fully qualified URL
     if (isset($parsedUrl['host'])) {
         $uriPrefix = '';
     } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
     }
     if ($absolute) {
         // If full URL has no scheme we add the same scheme as used by the site
         // so we have an absolute URL also usable outside of browser scope (e.g. in an email message)
         if (isset($parsedUrl['host']) && !isset($parsedUrl['scheme'])) {
             $uriPrefix = (GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https:' : 'http:') . $uriPrefix;
         }
         return GeneralUtility::locationHeaderUrl($uriPrefix . $imageUrl);
     } else {
         return $uriPrefix . $imageUrl;
     }
 }
Exemple #7
0
 /**
  * Render for given File(Reference) HTML output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options controls = TRUE/FALSE (default TRUE), autoplay = TRUE/FALSE (default FALSE), loop = TRUE/FALSE (default FALSE)
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false)
 {
     // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
     if (!isset($options['autoplay']) && $file instanceof FileReference) {
         $autoplay = $file->getProperty('autoplay');
         if ($autoplay !== null) {
             $options['autoplay'] = $autoplay;
         }
     }
     $attributes = [];
     if ((int) $width > 0) {
         $attributes[] = 'width="' . (int) $width . '"';
     }
     if ((int) $height > 0) {
         $attributes[] = 'height="' . (int) $height . '"';
     }
     if (!isset($options['controls']) || !empty($options['controls'])) {
         $attributes[] = 'controls';
     }
     if (!empty($options['autoplay'])) {
         $attributes[] = 'autoplay';
     }
     if (!empty($options['muted'])) {
         $attributes[] = 'muted';
     }
     if (!empty($options['loop'])) {
         $attributes[] = 'loop';
     }
     foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
         if (!empty($options[$key])) {
             $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
         }
     }
     return sprintf('<video%s><source src="%s" type="%s"></video>', empty($attributes) ? '' : ' ' . implode(' ', $attributes), htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)), $file->getMimeType());
 }
 /**
  * @return string
  */
 public function getPublicUrl()
 {
     return $this->resource->getPublicUrl(true);
 }
Exemple #9
0
 /**
  * Get the cropped image by File Object
  *
  * @param FileInterface $file
  * @param string $ratio
  *
  * @return string The new filename
  */
 public function getCroppedImageSrcByFile(FileInterface $file, $ratio)
 {
     return $this->getCroppedImageSrcBySrc($file->getPublicUrl(), $ratio, $file->getProperty('focus_point_x'), $file->getProperty('focus_point_y'));
 }