- public function cacheImageDimensions($identifyResult) {
- // Create md5 hash of filemtime and filesize
- $fileStatus = stat($identifyResult[3]);
- $md5Hash = md5($fileStatus['mtime'] . $fileStatus['size']);
- $result = FALSE;
- if ($md5Hash) {
- $fieldArray = array(
- 'md5hash' => $md5Hash,
- 'md5filename' => md5($identifyResult[3]),
- 'tstamp' => $GLOBALS['EXEC_TIME'],
- 'filename' => $identifyResult[3],
- 'imagewidth' => $identifyResult[0],
- 'imageheight' => $identifyResult[1]
+ public function cacheImageDimensions(array $identifyResult) {
+ $filePath = $identifyResult[3];
+ $statusHash = $this->generateCacheKeyForImageFile($filePath);
+
+ /** @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $cache */
+ $cache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_imagesizes');
+ $imageDimensions = array(
+ 'hash' => $statusHash,
+ 'imagewidth' => $identifyResult[0],
+ 'imageheight' => $identifyResult[1],
+ );
+ $cache->set($statusHash, $imageDimensions);
+
+ return TRUE;
+ }
+
+ /**
+ * Fetches the cached image dimensions from the cache. Does not check if the image file exists.
+ *
+ * @param string $filePath the image file path
+ *
+ * @return array|bool an array where [0]/[1] is w/h, [2] is extension and [3] is the file name,
+ * or FALSE for a cache miss
+ */
+ public function getCachedImageDimensions($filePath) {
+ $statusHash = $this->generateCacheKeyForImageFile($filePath);
+ /** @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $cache */
+ $cache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_imagesizes');
+ $cachedImageDimensions = $cache->get($statusHash);
+ if (!isset($cachedImageDimensions['hash'])) {
+ return FALSE;
+ }
+
+ if ($cachedImageDimensions['hash'] !== $statusHash) {
+ // The file has changed. Delete the cache entry.
+ $cache->remove($filePath);
+ $result = FALSE;
+ } else {
+ preg_match('/([^\\.]*)$/', $filePath, $imageExtension);
+ $result = array(
+ (int)$cachedImageDimensions['imagewidth'],
+ (int)$cachedImageDimensions['imageheight'],
+ strtolower($imageExtension[0]),
+ $filePath