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 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');
70 office 15 require_once('vendor/was/utilities/src/formats/kvp/kvp.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) {
82 office 36 $value = urlencode($key)."=".urlencode($value);
2 eva 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  
70 office 68  
2 eva 69 ####
11 eva 70 # II. Convert the image data to a PNG of size 512x512
2 eva 71 $im = imagescale(
72 imagecreatefromstring(
73 base64_decode(
82 office 74 urldecode(
2 eva 75 wasKeyValueGet(
76 "data",
77 $return
78 )
79 )
80 )
81 ),
82 512,
83 512
84 );
85  
86 ####
11 eva 87 # III. Output the Base64 encoded image for AJAX.
2 eva 88 ob_start();
89 imagepng($im);
90 $png = ob_get_contents();
91 imagedestroy($im);
92 ob_end_clean();
93  
94 echo base64_encode($png);
95  
96 ?>
97