2 // FINAL, RUNNING ... id# 2105641
3 // Comments, requests and bugs na moj mail ;) dakujem.
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);
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;
15 default: return (false); break;
19 function __cin_create_tmp_image($_src_f, $_dest_f, $_img_t, $_img_w) {
22 case 'gif': $_img_c_func = 'imagecreatefromgif'; break;
23 case 'jpg': $_img_c_func = 'imagecreatefromjpeg'; break;
24 case 'png': $_img_c_func = 'imagecreatefrompng'; break;
26 default: return (false); break;
29 $_src_i = $_img_c_func($_src_f);
30 $_src_w = imagesx($_src_i);
31 $_src_h = imagesy($_src_i);
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)));
36 $_dest_i = imagecreatetruecolor($_dest_w, $_dest_h);
38 imagecopyresampled($_dest_i, $_src_i, 0, 0, 0, 0, $_dest_w, $_dest_h, $_src_w, $_src_h);
40 imagegif($_dest_i, $_dest_f);
41 chmod($_dest_f, 0664);
44 imagedestroy($dest_i);
49 function configure_image() {
52 if (empty($_FILES['description_image'])) {
53 $error = '#00: Invalid file supplied.';
57 // if is owner, find out type of the image
58 if ($node['node_permission'] == 'owner') {
60 if (!($_img_t = __cin_get_img_type($_FILES['description_image']))) {
61 $error = '#01: Invalid file format (only JPEG, GIF & PNG are allowed)';
65 $_WEBROOT_PATH = realpath(dirname(__FILE__).'/../..');
66 $_PROCESS_IMG_PATH = $_WEBROOT_PATH.'/process-img';
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']);
72 if (!is_uploaded_file($_FILES['description_image']['tmp_name'])) {
73 $error = '#02: Invalid file upload';
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!';
82 // if (!move_uploaded_file($_FILES['description_image']['tmp_name'], $_prepared_fname)) {
83 // $error = '#04: Error moving uploaded file!';
87 // chmod($_prepared_fname, 0664);
88 // rename($_prepared_fname, substr($_prepared_fname, 0, -7));