corrade-http-templates – Blame information for rev 82

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 eva 1 <?php
2  
3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
5 ###########################################################################
6 ## This is a script that uses Corrade's HTTP server to get the UUID of ##
7 ## the current region map, then downloads the map as a PNG which then ##
8 ## gets encoded to a Base64 string and echoed from this script. ##
9 ###########################################################################
10  
11 ###########################################################################
12 ## CONFIGURATION ##
13 ###########################################################################
14  
12 eva 15 # The configuration file for this script containing the settings.
16 require_once('config.php');
77 office 17 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
18 require_once('vendor/was/utilities/src/formats/csv/csv.php');
2 eva 19  
20 ###########################################################################
21 ## INTERNALS ##
22 ###########################################################################
23  
24 ####
25 # I. Get the UUID of the map image for the current region
26 $params = array(
27 'command' => 'getgridregiondata',
28 'group' => $GROUP,
29 'password' => $PASSWORD,
30 'data' => 'MapImageID'
31 );
32 array_walk($params,
33 function(&$value, $key) {
34 $value = urlencode($key)."=".urlencode($value);
35 }
36 );
37 $postvars = implode('&', $params);
38 if (!($curl = curl_init())) {
39 print 0;
40 return;
41 }
42  
43 curl_setopt($curl, CURLOPT_URL, $URL);
44 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
45 curl_setopt($curl, CURLOPT_POST, true);
46 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
47 $return = curl_exec($curl);
48 curl_close($curl);
49  
50 $success = urldecode(
51 wasKeyValueGet(
52 "success",
53 $return
54 )
55 );
56  
57 // Unable to retrieve the map image?
58 if($success == 'False') return -1;
59  
60 $mapUUID = wasCSVToArray(
61 urldecode(
62 wasKeyValueGet(
63 "data",
64 $return
65 )
66 )
67 )[1];
68  
69 ####
70 # II. Download the map image as a PNG file.
71 $params = array(
72 'command' => 'download',
73 'group' => $GROUP,
74 'password' => $PASSWORD,
75 'item' => $mapUUID,
76 'type' => 'Texture',
77 'format' => 'Png'
78 );
79 array_walk($params,
80 function(&$value, $key) {
82 office 81 $value = urlencode($key)."=".urlencode($value);
2 eva 82 }
83 );
84 $postvars = implode('&', $params);
85 if (!($curl = curl_init())) {
86 print 0;
87 return;
88 }
89 curl_setopt($curl, CURLOPT_URL, $URL);
90 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
91 curl_setopt($curl, CURLOPT_POST, true);
92 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
93 $return = curl_exec($curl);
94 curl_close($curl);
95  
96 $success = urldecode(
97 wasKeyValueGet(
98 "success",
99 $return
100 )
101 );
102  
103 // Unable to download the region map texture?
104 if($success == 'False') return -1;
105  
106 ####
107 # III. Convert the image data to a PNG of size 512x512
108 $im = imagescale(
109 imagecreatefromstring(
110 base64_decode(
82 office 111 urldecode(
2 eva 112 wasKeyValueGet(
113 "data",
114 $return
115 )
116 )
117 )
118 ),
119 512,
120 512
121 );
122  
123 ####
124 # VI. Output the Base64 encoded image for AJAX.
125 ob_start();
126 imagepng($im);
127 $png = ob_get_contents();
128 imagedestroy($im);
129 ob_end_clean();
130  
131 echo base64_encode($png);
132  
133 ?>
134