mirror of
https://github.com/msikma/pokesprite.git
synced 2026-09-07 01:45:11 -05:00
Modifications and fixes
This commit is contained in:
@@ -13,9 +13,13 @@
|
||||
# This script requires libpuzzle to be compiled and present.
|
||||
# See <https://github.com/jedisct1/libpuzzle> for more information.
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$verbose = false;
|
||||
$show_hits = true;
|
||||
$dir_old = @$argv[1];
|
||||
$dir_new = @$argv[2];
|
||||
$treshold = 0.066;
|
||||
$GLOBALS['file_exts'] = array('jpg', 'png', 'jpeg', 'gif');
|
||||
|
||||
if (!isset($dir_old) || !isset($dir_new)) {
|
||||
@@ -33,32 +37,56 @@ $imgs_new = iterate_dir($dir_new);
|
||||
|
||||
$unique_new_imgs = array();
|
||||
|
||||
$counter = 0;
|
||||
$total = count($imgs_old) * count($imgs_new);
|
||||
|
||||
print('old: `'.$dir_old.'\' contains '.count($imgs_old).' image files.'.PHP_EOL);
|
||||
print('new: `'.$dir_new.'\' contains '.count($imgs_new).' image files.'.PHP_EOL);
|
||||
print(PHP_EOL.'We will make '.(count($imgs_old) * count($imgs_new)).' comparisons.'.PHP_EOL);
|
||||
|
||||
if ($verbose) {
|
||||
print(PHP_EOL);
|
||||
}
|
||||
$counter_new = 0;
|
||||
foreach ($imgs_new as $img_new_path => $img_new_info) {
|
||||
foreach ($imgs_old as $img_old_path => $img_old_info) {
|
||||
$diff = get_img_diff($img_new_path, $img_old_path);
|
||||
if ($verbose) {
|
||||
print('comparing: '.$img_new_path.' to '.$img_old_path.': diff: '.$diff.PHP_EOL);
|
||||
if ($verbose || $show_hits) {
|
||||
$perc = ($counter / $total);
|
||||
if ($perc >= 1) {
|
||||
$perc = ' 100%';
|
||||
}
|
||||
if ($perc < 1) {
|
||||
$perc = sprintf('%04.1f%%', $perc * 100);
|
||||
}
|
||||
}
|
||||
if ($verbose) {
|
||||
print('['.$perc.'] comparing: `'.$img_new_path.'\' to `'.$img_old_path.'\': diff: '.$diff.PHP_EOL);
|
||||
}
|
||||
$counter += 1;
|
||||
|
||||
if ($diff < 0.01) {
|
||||
if ($diff < $treshold) {
|
||||
// Found duplicate. We're looking for images that do not have duplicates.
|
||||
$counter_new += 1;
|
||||
$counter = $counter_new * count($imgs_old);
|
||||
continue(2);
|
||||
}
|
||||
}
|
||||
if ($show_hits) {
|
||||
print('['.$perc.'] found unique image: `'.$img_new_path.'\'.'.PHP_EOL);
|
||||
}
|
||||
$counter_new += 1;
|
||||
$unique_new_imgs[$img_new_path] = $img_new_info;
|
||||
}
|
||||
|
||||
if ($verbose || $show_hits) {
|
||||
print('[ 100%] done.'.PHP_EOL);
|
||||
}
|
||||
if (empty($unique_new_imgs)) {
|
||||
print(PHP_EOL.'No unique images found.');
|
||||
}
|
||||
else {
|
||||
print(PHP_EOL.'Amount of unique images found: '.count($unique_new_imgs).PHP_EOL.PHP_EOL);
|
||||
print(PHP_EOL.'Amount of unique images found in `new\' directory: '.count($unique_new_imgs).PHP_EOL.PHP_EOL);
|
||||
foreach ($unique_new_imgs as $path => $img) {
|
||||
print(' '.$path.PHP_EOL);
|
||||
}
|
||||
@@ -71,7 +99,7 @@ function iterate_dir($dir)
|
||||
try {
|
||||
$dir_it = new \DirectoryIterator($dir);
|
||||
} catch (Exception $e) {
|
||||
print('error: can\'t open dir: '.$dir);
|
||||
print('error: can\'t open directory: '.$dir);
|
||||
continue;
|
||||
}
|
||||
foreach ($dir_it as $file) {
|
||||
@@ -98,7 +126,7 @@ function iterate_dir($dir)
|
||||
|
||||
function get_img_diff($new, $old)
|
||||
{
|
||||
$diff = trim(exec('puzzle-diff '.$new.' '.$old.' 2>&1', $output, $code));
|
||||
$diff = trim(exec('puzzle-diff "'.$new.'" "'.$old.'" 2>&1', $output, $code));
|
||||
if ($code !== 0) {
|
||||
print(PHP_EOL.'find_new_images.php: error: couldn\'t run the `puzzle-diff\' script'.PHP_EOL);
|
||||
die();
|
||||
|
||||
Reference in New Issue
Block a user