Пример #1
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)
 {
     $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;
 }
Пример #2
0
    /**
     * Creates a color image selector
     *
     * @return void
     * @todo Define visibility
     */
    public function colorImage()
    {
        // Handling color-picker image if any:
        if (!$this->imageError) {
            if ($this->pickerImage) {
                if (GeneralUtility::_POST('coords_x')) {
                    $this->colorValue = '#' . $this->getIndex(\TYPO3\CMS\Core\Imaging\GraphicalFunctions::imageCreateFromFile($this->pickerImage), GeneralUtility::_POST('coords_x'), GeneralUtility::_POST('coords_y'));
                }
                $pickerFormImage = '
				<p class="c-head">' . $GLOBALS['LANG']->getLL('colorpicker_fromImage', TRUE) . '</p>
				<input type="image" src="../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->pickerImage) . '" name="coords" style="cursor:crosshair;" /><br />';
            } else {
                $pickerFormImage = '';
            }
        } else {
            $pickerFormImage = '
			<p class="c-head">' . htmlspecialchars($this->imageError) . '</p>';
        }
        return $pickerFormImage;
    }