-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoSVG.command
More file actions
executable file
·66 lines (58 loc) · 1.58 KB
/
toSVG.command
File metadata and controls
executable file
·66 lines (58 loc) · 1.58 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
#!/usr/bin/php
<?php
$step = 1;
fwrite(STDOUT, "Omzetten naar vectoren \r\n");
chdir( dirname ( __FILE__ ) );
$file = 'download.png';
$spec = getimagesize($file);
$w = $spec[0];
$h = $spec[1];
$original = imagecreatefrompng($file);
function fromR($R, $G, $B){
$R = dechex($R);
if (strlen($R) < 2) {
$R = "0$R";
}
$G = dechex($G);
if (strlen($G) < 2) {
$G = "0$G";
}
$B = dechex($B);
if (strlen($B) < 2) {
$B = "0$B";
}
return "#$R$G$B";
}
$handle = fopen("export/export.svg", "w+");
ob_start();
?>
<svg style="overflow: hidden; position: relative;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="<?php echo $w ?>" version="1.1" height="<?php echo $h ?>">
<?php
for($x = 0; $x < $w; $x += $step) {
$color = '#000000';
$off = 0;
fwrite(STDOUT, ".");
for($y = 0; $y < $h; $y += 1) {
$index = imagecolorat($original, $x, $y);
$rgb = imagecolorsforindex($original, $index);
$hex = fromR($rgb['red'], $rgb['green'], $rgb['blue']);
if($hex != $color) {
if($color != '#ffffff') {
$height = $y - $off;
echo "<rect transform='matrix(1,0,0,1,0,0)' x='$x' y='$off' width='1' height='$height' r='0' rx='0' ry='0' fill='$color'></rect>";
}
$color = $hex;
$off = $y;
}
}
if($color != '#ffffff') {
$height = $h - $off;
echo "<rect transform='matrix(1,0,0,1,0,0)' x='$x' y='$off' width='1' height='$height' r='0' rx='0' ry='0' fill='$color'></rect>";
}
};
?>
</svg>
<?php
fwrite($handle, ob_get_clean());
fclose($handle);
?>