Skip to content

Instantly share code, notes, and snippets.

@pkdavies
Created July 6, 2012 15:40
Show Gist options
  • Save pkdavies/3060960 to your computer and use it in GitHub Desktop.
Save pkdavies/3060960 to your computer and use it in GitHub Desktop.
PHP based high resolution image combiner
<?php
$oldpath = "./in/";
$newpath = "./out/";
$dir_iterator = new RecursiveDirectoryIterator($oldpath);
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
$files_all = $files_copied = $files_replaced = 0;
foreach ($iterator as $file) {
if ($file->isFile()) {
$size = $file->getSize();
$newfile = strtolower($file->getFilename());
if (file_exists($newpath.$newfile) && filesize($newpath.$newfile) < $size){
if (!copy($file->getPathname(), $newpath.$newfile)) {
echo "failed to copy...\n";
} else {
echo "found larger file and copied...".$file->getPathname()."\n";
$files_replaced++;
}
} else {
if (!copy($file->getPathname(), $newpath.$newfile)) {
echo "failed to copy...\n";
} else {
echo "file copied...".$file->getPathname()."\n";
$files_copied++;
}
}
}
$files_all++;
}
echo "---------- ALL DONE -------------------\n";
echo "All files = $files_all \n";
echo "Copied files = $files_copied \n";
echo "Replaced files = $files_replaced \n";
echo "---------------------------------------\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment