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 pathcrawler_archive.php
More file actions
70 lines (47 loc) · 1.45 KB
/
crawler_archive.php
File metadata and controls
70 lines (47 loc) · 1.45 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
<?php
require_once 'ImageSearch.php';
require_once 'ImageProcessor.php';
$limit = 200;
//$subjectList = ['dog', 'cat']; //, 'fish', 'horse', 'bird', 'goat', 'sheep', 'mouse', 'elephant', 'fox', 'wolf'];
$subjectList = ['landscape', 'mountains', 'river', 'lake'];
$imageSearch = new ImageSearch();
$imageProcessor = new ImageProcessor();
$colorIndexCounters = [];
foreach ($subjectList as $subject) {
$page = 1;
while (true) {
$result = $imageSearch->search($subject, $limit, $page);
if (empty($result['hits'])) {
break;
}
foreach ($result['hits'] as $image) {
$data = $imageProcessor->processImage($image);
if (empty($data['path'])) {
continue;
}
$id = $data['colors']['index'];
$newFilePath = '/home/tessera/source_images/nature/' . $id;
$counterFileName = $newFilePath . '/counter';
if (!file_exists($newFilePath)) {
mkdir($newFilePath, 0777, true);
}
if (!isset($colorIndexCounters[$id])) {
if (file_exists($counterFileName)) {
$colorIndexCounters[$id] = file_get_contents($counterFileName);
} else {
$colorIndexCounters[$id] = 0;
}
}
if (file_exists($counterFileName))
{
unlink($counterFileName);
}
$name = $newFilePath . '/' . $colorIndexCounters[$id]++ . '.jpg';
file_put_contents($counterFileName, $colorIndexCounters[$id]);
if (copy($data['path'], $name)) {
echo PHP_EOL . $subject . ' - ' . $result['total'] . ' - ' . $name;
}
}
$page++;
}
}