get_image_link fix
[mirrors/Kyberia-bloodline.git] / wwwroot / inc / eventz / configure_image.inc
1 <?php
2 // FINAL, RUNNING ... id# 2105641
3 // Comments, requests and bugs na moj mail ;) dakujem.
4
5 function __cin_get_img_type(&$_file_i) {
6 list($_mime_type, $_mime_subtype) = explode('/', $_file_i['type']);
7 if ($_mime_type != 'image') return (false);
8
9 $_img_i = getimagesize($_file_i['tmp_name']);
10 switch ($_mime_subtype) {
11 case 'gif': return (($_img_i[2] == 1)?'gif':false); break;
12 case 'jpeg': return (($_img_i[2] == 2)?'jpg':false); break;
13 case 'png': return (($_img_i[2] == 3)?'png':false); break;
14
15 default: return (false); break;
16 }
17 }
18
19 function __cin_create_tmp_image($_src_f, $_dest_f, $_img_t, $_img_w) {
20
21 switch ($_img_t) {
22 case 'gif': $_img_c_func = 'imagecreatefromgif'; break;
23 case 'jpg': $_img_c_func = 'imagecreatefromjpeg'; break;
24 case 'png': $_img_c_func = 'imagecreatefrompng'; break;
25
26 default: return (false); break;
27 }
28
29 $_src_i = $_img_c_func($_src_f);
30 $_src_w = imagesx($_src_i);
31 $_src_h = imagesy($_src_i);
32
33 $_dest_w = floor($_src_w / ($_src_w / min($_src_w, $_img_w)));
34 $_dest_h = floor($_src_h / ($_src_w / min($_src_w, $_img_w)));
35
36 $_dest_i = imagecreatetruecolor($_dest_w, $_dest_h);
37
38 imagecopyresampled($_dest_i, $_src_i, 0, 0, 0, 0, $_dest_w, $_dest_h, $_src_w, $_src_h);
39
40 imagegif($_dest_i, $_dest_f);
41 chmod($_dest_f, 0664);
42
43 imagedestroy($src_i);
44 imagedestroy($dest_i);
45
46 return (true);
47 }
48
49 function configure_image() {
50 global $error, $node;
51
52 if (empty($_FILES['description_image'])) {
53 $error = '#00: Invalid file supplied.';
54 return (false);
55 }
56
57 // if is owner, find out type of the image
58 if ($node['node_permission'] == 'owner') {
59
60 if (!($_img_t = __cin_get_img_type($_FILES['description_image']))) {
61 $error = '#01: Invalid file format (only JPEG, GIF & PNG are allowed)';
62 return (false);
63 }
64 // XXX hard coded
65 $_WEBROOT_PATH = realpath(dirname(__FILE__).'/../..');
66 $_PROCESS_IMG_PATH = $_WEBROOT_PATH.'/process-img';
67
68 $_required_dims = ($node['node_id'] == $_SESSION['user_id'])?50:NODE_IMAGE_WIDTH;
69 $_prepared_fname = sprintf('%s/prepared/%03s_%s.gif.upload', $_PROCESS_IMG_PATH, $_required_dims, $node['node_id']);
70 $_nodeimg_fname = sprintf('%s/'.SYSTEM_IMAGES.'/nodes/%s/%s/%d.gif', $_WEBROOT_PATH, $node['node_id'][0], $node['node_id'][1], $node['node_id']);
71
72 if (!is_uploaded_file($_FILES['description_image']['tmp_name'])) {
73 $error = '#02: Invalid file upload';
74 return (false);
75 }
76
77 if (!__cin_create_tmp_image($_FILES['description_image']['tmp_name'], $_nodeimg_fname, $_img_t, $_required_dims)) {
78 $error = '#03: Unable to create temporary thumbnail image!';
79 return (false);
80 }
81
82 // if (!move_uploaded_file($_FILES['description_image']['tmp_name'], $_prepared_fname)) {
83 // $error = '#04: Error moving uploaded file!';
84 // return (false);
85 // }
86
87 // chmod($_prepared_fname, 0664);
88 // rename($_prepared_fname, substr($_prepared_fname, 0, -7));
89
90 }
91
92 return (true);
93 }
94 ?>
This page took 1.134329 seconds and 4 git commands to generate.