From 5f504404ef55e4a871368d180a66db88c1a87628 Mon Sep 17 00:00:00 2001 From: Aleksey Razbakov Date: Wed, 1 Feb 2017 18:30:45 +0100 Subject: [PATCH] filter only images in input --- optimize-images.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/optimize-images.php b/optimize-images.php index fa95310..e1a18f1 100755 --- a/optimize-images.php +++ b/optimize-images.php @@ -26,10 +26,17 @@ function recurseImages($dir, &$initialBytes, &$bytesSaved) if (is_dir($current_file)) { $stack[] = $current_file; } else { - $initialBytes += filesize($current_file); - optimizeImage($current_file); - $bytesSaved += filesize($current_file); - $images++; + switch (strtoupper(pathinfo($current_file, PATHINFO_EXTENSION))) { + case 'GIF': + case 'PNG': + case 'JPG': + case 'JPEG': + $initialBytes += filesize($current_file); + optimizeImage($current_file); + $bytesSaved += filesize($current_file); + $images++; + break; + } } } }