-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.php
More file actions
67 lines (49 loc) · 1.45 KB
/
run.php
File metadata and controls
67 lines (49 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
64
65
66
67
<?php
require_once 'vendor/autoload.php';
use Intervention\Image\ImageManagerStatic as Image;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Fill;
$image = $argv[1];
if (!$image) {
echo "please input a image file \n";
}
$input = Image::make($image);
$imageName = explode('/', $image);
$imageName = array_pop($imageName);
$outputName = "output/{$imageName}.xlsx";
$height = $input->getHeight();
$width = $input->getWidth();
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getDefaultColumnDimension()->setWidth(3);
$map = [];
$start = time();
show('----start----');
for ($i = 0; $i < $width; $i++) {
for ($j = 0; $j < $height; $j++) {
$color = $input->pickColor($i, $j, 'hex');
$color = substr($color, 1);
$cell = $sheet->getCellByColumnAndRow($i, $j);
$cell->getStyle()->getFill()->applyFromArray(
[
'fillType' => Fill::FILL_SOLID,
'startColor' => [
'rgb' => $color
],
]
);
}
$per = number_format(100 * ($i + 1) / $width, 2);
show($per . " %");
}
$writer = new Xlsx($spreadsheet);
$writer->save($outputName);
show('cost ' . (time() - $start) . ' s');
show("surprise >>>> {$outputName} <<<<");
show('----end----');
function show($msg)
{
$date = date('Y-m-d H:i:s');
echo "[{$date}] $msg\n";
}