This repository was archived by the owner on Mar 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge.php
More file actions
77 lines (56 loc) · 1.35 KB
/
merge.php
File metadata and controls
77 lines (56 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
$folder = '/mnt/resource/source_images/';
//$sourceCategories = ['animals_2', 'new_animals'];
//
//$target = 'animals_merged';
$sourceCategories = ['animals_merged', 'new_people', 'buildings', 'music', 'new_travel', 'new_fashion', 'new_science'];
$target = 'all_2';
$targetFolder = $folder . $target . '/';
$idCounters[] = 0;
$i = 0;
foreach ($sourceCategories as $category)
{
$parentFolder = $folder . $category;
$imageColorFolderList = getFolderContentList($parentFolder);
if (empty($imageColorFolderList))
{
continue;
}
foreach ($imageColorFolderList as $colorId)
{
$targetColorFolder = $targetFolder . $colorId;
if (!isset($idCounters[$colorId]))
{
$idCounters[$colorId] = 0;
}
$colorFolder = $parentFolder . '/' . $colorId;
$files = getFolderContentList($colorFolder);
if (!file_exists($targetColorFolder))
{
mkdir($targetColorFolder, 0777, true);
}
foreach ($files as $file)
{
$oldFile = $colorFolder . '/' . $file;
$newFile = $targetColorFolder . '/' . $idCounters[$colorId]++ . '.jpg';
copy($oldFile, $newFile);
echo ' ' . $i++;
}
}
}
function getFolderContentList($folder)
{
$list = [];
if ($handle = opendir($folder))
{
while (false !== ($entry = readdir($handle)))
{
if ($entry != "." && $entry != "..")
{
$list[] = $entry;
}
}
closedir($handle);
}
return $list;
}