Last active
November 20, 2017 07:04
-
-
Save pranid/25917edecdffb19695b2a2815dfee1b4 to your computer and use it in GitHub Desktop.
Bulk Images Compressor for Servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getFolderFiles($dir){ | |
$quality = 60; | |
$scan_dir = scandir($dir); | |
echo '<ol>'; | |
foreach($scan_dir as $file_path){ | |
$destination = $dir."\/".$file_path; | |
$source = $dir."\/".$file_path; | |
if($file_path != '.' && $file_path != '..'){ | |
echo '<li>'.$file_path; | |
if(is_dir($dir.'/'.$file_path)) { | |
getFolderFiles($dir.'/'.$file_path); | |
} else { | |
compress($source, $destination, $quality); | |
} | |
echo '</li>'; | |
} | |
} | |
echo '</ol>'; | |
} | |
function compress($source, $destination, $quality) { | |
$info = getimagesize($source); | |
if ($info['mime'] == 'image/jpeg') | |
$image = imagecreatefromjpeg($source); | |
/*elseif ($info['mime'] == 'image/gif') | |
$image = imagecreatefromgif($source); | |
elseif ($info['mime'] == 'image/png') | |
$image = imagecreatefrompng($source);*/ | |
if(isset($image)) { | |
imagejpeg($image, $destination, $quality); | |
return $destination; | |
} | |
} | |
getFolderFiles('You media Folder Path Here'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfectly. Thank you. :)