corrade-http-templates – Blame information for rev 11
?pathlinks?
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 can be used to download a texture using Corrade ## |
||
7 | ## and the "download" Corrde command. ## |
||
8 | ########################################################################### |
||
9 | |||
10 | ########################################################################### |
||
11 | ## CONFIGURATION ## |
||
12 | ########################################################################### |
||
13 | |||
11 | eva | 14 | require_once('config.php'); |
15 | require_once('functions.php'); |
||
2 | eva | 16 | |
17 | ########################################################################### |
||
18 | ## INTERNALS ## |
||
19 | ########################################################################### |
||
20 | |||
11 | eva | 21 | if(!isset($_POST['uuid'])) return; |
22 | $uuid = $_POST['uuid']; |
||
2 | eva | 23 | |
24 | #### |
||
11 | eva | 25 | # I. Download the map image as a PNG file. |
2 | eva | 26 | $params = array( |
27 | 'command' => 'download', |
||
28 | 'group' => $GROUP, |
||
29 | 'password' => $PASSWORD, |
||
30 | 'item' => $uuid, |
||
31 | 'type' => 'Texture', |
||
32 | 'format' => 'Png' |
||
33 | ); |
||
34 | array_walk($params, |
||
35 | function(&$value, $key) { |
||
36 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
37 | } |
||
38 | ); |
||
39 | $postvars = implode('&', $params); |
||
40 | if (!($curl = curl_init())) { |
||
41 | print 0; |
||
42 | return; |
||
43 | } |
||
44 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
45 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
46 | curl_setopt($curl, CURLOPT_POST, true); |
||
47 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
48 | $return = curl_exec($curl); |
||
49 | curl_close($curl); |
||
50 | |||
51 | $success = urldecode( |
||
52 | wasKeyValueGet( |
||
53 | "success", |
||
54 | $return |
||
55 | ) |
||
56 | ); |
||
57 | |||
58 | if($success == 'False') { |
||
59 | echo 'Unable to download texture: '.urldecode( |
||
60 | wasKeyValueGet( |
||
61 | "success", |
||
62 | $return |
||
63 | ) |
||
64 | ); |
||
65 | die; |
||
66 | } |
||
67 | |||
68 | #### |
||
11 | eva | 69 | # II. Convert the image data to a PNG of size 512x512 |
2 | eva | 70 | $im = imagescale( |
71 | imagecreatefromstring( |
||
72 | base64_decode( |
||
73 | rawurldecode( |
||
74 | wasKeyValueGet( |
||
75 | "data", |
||
76 | $return |
||
77 | ) |
||
78 | ) |
||
79 | ) |
||
80 | ), |
||
81 | 512, |
||
82 | 512 |
||
83 | ); |
||
84 | |||
85 | #### |
||
11 | eva | 86 | # III. Output the Base64 encoded image for AJAX. |
2 | eva | 87 | ob_start(); |
88 | imagepng($im); |
||
89 | $png = ob_get_contents(); |
||
90 | imagedestroy($im); |
||
91 | ob_end_clean(); |
||
92 | |||
93 | echo base64_encode($png); |
||
94 | |||
95 | ?> |
||
96 |