TYPO3 CMS  TYPO3_6-2
ImageService.php
Go to the documentation of this file.
1 <?php
3 
23 
28 
33  protected $resourceFactory;
34 
40 
49  public function applyProcessingInstructions($image, $processingInstructions) {
50  if (is_callable(array($image, 'getOriginalFile'))) {
51  // Get the original file from the file reference
52  $image = $image->getOriginalFile();
53  }
54 
55  $processedImage = $image->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingInstructions);
56  $this->setCompatibilityValues($processedImage);
57 
58  return $processedImage;
59  }
60 
68  public function getImageUri(FileInterface $image) {
69  $imageUrl = $image->getPublicUrl();
70 
71  // no prefix in case of an already fully qualified URL (having a schema)
72  // We need to fix the dection for PHP 5.4.6 and below as the host detection is broken
73  if (parse_url($imageUrl, PHP_URL_HOST) !== NULL || strpos($imageUrl, '//') === 0) {
74  $uriPrefix = '';
75  } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
76  $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
77  } else {
78  $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
79  }
80 
81  return $uriPrefix . $imageUrl;
82  }
83 
98  public function getImage($src, $image, $treatIdAsReference) {
99  if (is_null($image)) {
100  $image = $this->getImageFromSourceString($src, $treatIdAsReference);
101  } elseif (is_callable(array($image, 'getOriginalResource'))) {
102  // We have a domain model, so we need to fetch the FAL resource object from there
103  $image = $image->getOriginalResource();
104  }
105 
106  if (!($image instanceof File || $image instanceof FileReference)) {
107  throw new \UnexpectedValueException('Supplied file object type ' . get_class($image) . ' must be File or FileReference.', 1382687163);
108  }
109 
110  return $image;
111  }
112 
120  protected function getImageFromSourceString($src, $treatIdAsReference) {
121  if ($this->environmentService->isEnvironmentInBackendMode() && substr($src, 0, 3) === '../') {
122  $src = substr($src, 3);
123  }
125  if ($treatIdAsReference) {
126  $image = $this->resourceFactory->getFileReferenceObject($src);
127  } else {
128  $image = $this->resourceFactory->getFileObject($src);
129  }
130  } else {
131  // We have a combined identifier or legacy (storage 0) path
132  $image = $this->resourceFactory->retrieveFileOrFolderObject($src);
133  }
134  return $image;
135  }
136 
144  protected function setCompatibilityValues(ProcessedFile $processedImage) {
145  if ($this->environmentService->isEnvironmentInFrontendMode()) {
146  $imageInfo = $this->getCompatibilityImageResourceValues($processedImage);
147  $GLOBALS['TSFE']->lastImageInfo = $imageInfo;
148  $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3];
149  }
150  }
151 
160  protected function getCompatibilityImageResourceValues(ProcessedFile $processedImage) {
161  $hash = $processedImage->calculateChecksum();
162  if (isset($GLOBALS['TSFE']->tmpl->fileCache[$hash])) {
163  $compatibilityImageResourceValues = $GLOBALS['TSFE']->tmpl->fileCache[$hash];
164  } else {
165  $compatibilityImageResourceValues = array(
166  0 => $processedImage->getProperty('width'),
167  1 => $processedImage->getProperty('height'),
168  2 => $processedImage->getExtension(),
169  3 => $processedImage->getPublicUrl(),
170  'origFile' => $processedImage->getOriginalFile()->getPublicUrl(),
171  'origFile_mtime' => $processedImage->getOriginalFile()->getModificationTime(),
172  // This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder,
173  // in order for the setup-array to create a unique filename hash.
174  'originalFile' => $processedImage->getOriginalFile(),
175  'processedFile' => $processedImage,
176  'fileCacheHash' => $hash
177  );
178  }
179  return $compatibilityImageResourceValues;
180  }
181 }
getCompatibilityImageResourceValues(ProcessedFile $processedImage)
getPublicUrl($relativeToCurrentScript=FALSE)
applyProcessingInstructions($image, $processingInstructions)
setCompatibilityValues(ProcessedFile $processedImage)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getPublicUrl($relativeToCurrentScript=FALSE)
getImage($src, $image, $treatIdAsReference)
getImageFromSourceString($src, $treatIdAsReference)