From 6aa588813b268a9eec2509b470860f9a84992e91 Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Fri, 18 Nov 2022 14:54:15 +0100 Subject: [PATCH] BUGFIX: Handle empty files correctly in check Fixes #4 --- Classes/Service/ThumbnailOptimizationService.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Classes/Service/ThumbnailOptimizationService.php b/Classes/Service/ThumbnailOptimizationService.php index 94ea234..42c21eb 100644 --- a/Classes/Service/ThumbnailOptimizationService.php +++ b/Classes/Service/ThumbnailOptimizationService.php @@ -79,6 +79,14 @@ public function optimizeThumbnail(Thumbnail $thumbnail) fclose($resourceStream); fclose($temporaryFileHandle); + $filesizeOriginal = filesize($tmpFileInput); + if ((bool)$filesizeOriginal === false) { + $this->logger->error(sprintf('Creating temporary copy of original image "%s" resulted in empty file', $thumbnail->getOriginalAsset()->getLabel()), $output); + unlink($tmpFileInput); + unlink($tmpFileOptimized); + return; + } + $shellCommand = str_replace( ['{input}', '{output}'], [escapeshellarg($tmpFileInput), escapeshellarg($tmpFileOptimized)], @@ -96,11 +104,9 @@ public function optimizeThumbnail(Thumbnail $thumbnail) return; } - $filesizeOriginal = filesize($tmpFileInput); $filesizeOptimized = filesize($tmpFileOptimized); - - if ((bool)$filesizeOriginal === false || (bool)$filesizeOptimized === false) { - $this->logger->error(sprintf('Optimizing image "%s" with command "%s" resulted in empty files', $thumbnail->getOriginalAsset()->getLabel(), $shellCommand), $output); + if ((bool)$filesizeOptimized === false) { + $this->logger->error(sprintf('Optimizing image "%s" with command "%s" resulted in empty file', $thumbnail->getOriginalAsset()->getLabel(), $shellCommand), $output); unlink($tmpFileInput); unlink($tmpFileOptimized); return;