-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers_generator.php
More file actions
48 lines (44 loc) · 1.38 KB
/
numbers_generator.php
File metadata and controls
48 lines (44 loc) · 1.38 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
<?php
$json = file_get_contents( 'pokemon.json' );
$pokemons = json_decode( $json, true );
$dir = realpath(dirname(__FILE__));
foreach ( $pokemons as $k => $pokemon ) {
if ( $k <= 9 ) {
$id = "00$k";
} else if ( $k <= 99 ) {
$id = "0$k";
} else {
$id = $k;
}
$color = array();
foreach ( $pokemon['types'] as $t ) {
array_push($color, $t['color']);
}
// Get type color from pokemon
$primarycolor = $color[0];
list($r, $g, $b) = sscanf($primarycolor, "#%02x%02x%02x");
// Create transparant canvas
$img = imagecreatetruecolor(80, 80);
$color = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagefill($img, 0, 0, $color);
imagesavealpha($img, true);
// Define colors
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$circlecolor = imagecolorallocate($img, $r, $g, $b);
// Draw colored circle
imagefilledellipse($img, 40, 40, 80, 80, $circlecolor);
// Define text font
$font_path = "" . $dir . "/Aller_Rg.ttf";
$hasforms = isset( $pokemon['forms'] );
if ( $hasforms ) {
foreach ( $pokemon['forms'] as $f ) {
$protoform = $f['protoform'];
imagettftext($img, 20, 0, 18, 48, $white, $font_path, $id);
imagepng($img, "icons/numbers/pokemon_icon_" . $id . "_" . $protoform . ".png");
}
} else {
imagettftext($img, 20, 0, 18, 48, $white, $font_path, $id);
imagepng($img, "icons/numbers/pokemon_icon_" . $id . "_00.png");
}
}