2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
\r
6 /* Adaptive Technology Resource Centre / University of Toronto */
\r
7 /* http://atutor.ca */
\r
9 /* This program is free software. You can redistribute it and/or */
\r
10 /* modify it under the terms of the GNU General Public License */
\r
11 /* as published by the Free Software Foundation. */
\r
12 /************************************************************************/
\r
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
\r
16 function resize_image($src, $dest, $src_h, $src_w, $dest_h, $dest_w, $type, $src_x=0, $src_y=0) {
\r
17 $thumbnail_img = imagecreatetruecolor($dest_w, $dest_h);
\r
19 if ($type == 'gif') {
\r
20 $source = imagecreatefromgif($src);
\r
21 } else if ($type == 'jpg') {
\r
22 $source = imagecreatefromjpeg($src);
\r
24 $source = imagecreatefrompng($src);
\r
27 if ($src_x > 0 || $src_y > 0){
\r
28 imagecopyresized($thumbnail_img, $source, 0, 0, $src_x, $src_y, $dest_w, $dest_h, $src_w, $src_h);
\r
30 imagecopyresampled($thumbnail_img, $source, $src_x, $src_y, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
\r
33 if ($type == 'gif') {
\r
34 imagegif($thumbnail_img, $dest);
\r
35 } else if ($type == 'jpg') {
\r
36 imagejpeg($thumbnail_img, $dest, 75);
\r
38 imagepng($thumbnail_img, $dest, 7);
\r
42 // check if GD is installed
\r
43 if (!extension_loaded('gd')) {
\r
44 require(AT_INCLUDE_PATH.'header.inc.php');
\r
45 $msg->printInfos('FEATURE_NOT_AVAILABLE');
\r
46 require(AT_INCLUDE_PATH.'footer.inc.php');
\r
50 // check if folder exists, if not, create it
\r
51 if (!is_dir(AT_CONTENT_DIR.'/profile_pictures/profile')) {
\r
52 mkdir(AT_CONTENT_DIR.'/profile_pictures/profile');
\r
55 $gd_info = gd_info();
\r
56 $supported_images = array();
\r
57 if ($gd_info['GIF Create Support']) {
\r
58 $supported_images[] = 'gif';
\r
60 if ($gd_info['JPG Support']) {
\r
61 $supported_images[] = 'jpg';
\r
63 if ($gd_info['PNG Support']) {
\r
64 $supported_images[] = 'png';
\r
67 if (!$supported_images) {
\r
68 require(AT_INCLUDE_PATH.'header.inc.php');
\r
69 $msg->printInfos('FEATURE_NOT_AVAILABLE');
\r
70 require(AT_INCLUDE_PATH.'footer.inc.php');
\r
74 if (isset($_POST['cancel'])) {
\r
75 $msg->addFeedback('CANCELLED');
\r
76 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
78 } else if (isset($_POST['submit'])) {
\r
79 if (isset($_POST['delete']) && !$_FILES['file']['size']) {
\r
80 profile_image_delete($member_id);
\r
82 $msg->addFeedback('PROFILE_UPDATED');
\r
84 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
86 } else if ($_FILES['file']['error'] == UPLOAD_ERR_FORM_SIZE) {
\r
87 $msg->addError(array('FILE_MAX_SIZE', $_config['prof_pic_max_file_size'] . ' ' . _AT('bytes')));
\r
88 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
90 } else if (!$_FILES['file']['size']) {
\r
91 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
95 // check if this is a supported file type
\r
96 $filename = $stripslashes($_FILES['file']['name']);
\r
97 $path_parts = pathinfo($filename);
\r
98 $extension = strtolower($path_parts['extension']);
\r
99 $image_attributes = getimagesize($_FILES['file']['tmp_name']);
\r
101 if ($extension == 'jpeg') {
\r
102 $extension = 'jpg';
\r
105 if (!in_array($extension, $supported_images)) {
\r
106 $msg->addError(array('FILE_ILLEGAL', $extension));
\r
107 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
109 } else if ($image_attributes[2] > IMAGETYPE_PNG) {
\r
110 $msg->addError(array('FILE_ILLEGAL', $extension));
\r
111 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
115 // make sure under max file size
\r
116 if ($_FILES['file']['size'] > $_config['prof_pic_max_file_size']) {
\r
117 $msg->addError('FILE_MAX_SIZE');
\r
118 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
122 // delete the old images (if any)
\r
123 profile_image_delete($member_id);
\r
125 $new_filename = $member_id . '.' . $extension;
\r
126 $original_img = AT_CONTENT_DIR.'profile_pictures/originals/'. $new_filename;
\r
127 $profile_img = AT_CONTENT_DIR.'profile_pictures/profile/'. $new_filename;
\r
128 $thumbnail_img = AT_CONTENT_DIR.'profile_pictures/thumbs/'. $new_filename;
\r
131 if (!move_uploaded_file($_FILES['file']['tmp_name'], $original_img)) {
\r
132 $msg->addError('CANNOT_OVERWRITE_FILE');
\r
133 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
137 // resize the original and save it at $thumbnail_file
\r
138 $width = $image_attributes[0];
\r
139 $height = $image_attributes[1];
\r
141 $thumbnail_fixed_height = 60;
\r
142 $thumbnail_fixed_width = 60;
\r
144 if ($width > $height && $height > $thumbnail_fixed_height) {
\r
145 $thumbnail_height= $thumbnail_fixed_height;
\r
146 $thumbnail_width = intval($thumbnail_fixed_height * $width / $height);
\r
147 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
\r
149 resize_image($thumbnail_img, $thumbnail_img, $thumbnail_fixed_height, $thumbnail_fixed_width, $thumbnail_fixed_height, $thumbnail_fixed_width, $extension, ($thumbnail_width-$thumbnail_fixed_width)/2);
\r
150 } else if ($width <= $height && $width>$thumbnail_fixed_width) {
\r
151 $thumbnail_height = intval($thumbnail_fixed_width * $height / $width);
\r
152 $thumbnail_width = $thumbnail_fixed_width;
\r
153 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
\r
155 resize_image($thumbnail_img, $thumbnail_img, $thumbnail_fixed_height, $thumbnail_fixed_width, $thumbnail_fixed_height, $thumbnail_fixed_width, $extension, 0, ($thumbnail_height-$thumbnail_fixed_height)/2);
\r
157 // no resizing, just copy the image.
\r
158 // it's too small to resize.
\r
159 copy($original_img, $thumbnail_img);
\r
162 // resize the original and save it to profile
\r
163 $profile_fixed_height = 320;
\r
164 $profile_fixed_width = 240;
\r
165 if ($width > $height && $height>$profile_fixed_height) {
\r
166 $profile_width = intval($profile_fixed_height * $width / $height);
\r
167 $profile_height = $profile_fixed_height;
\r
168 resize_image($original_img, $profile_img, $height, $width, $profile_height, $profile_width, $extension);
\r
170 resize_image($profile_img, $profile_img, $profile_fixed_height, $profile_fixed_width, $profile_fixed_height, $profile_fixed_width, $extension, ($profile_width-$profile_fixed_width)/2);
\r
171 } else if ($width <= $height && $width > $profile_fixed_width) {
\r
172 $profile_width = $profile_fixed_width;
\r
173 $profile_height = intval($profile_fixed_width * $height / $width);
\r
174 resize_image($original_img, $profile_img, $height, $width, $profile_height, $profile_width, $extension);
\r
176 resize_image($profile_img, $profile_img, $profile_fixed_height, $profile_fixed_width, $profile_fixed_height, $profile_fixed_width, $extension, 0, ($profile_height-$profile_fixed_height)/2);
\r
178 // no resizing, just copy the image.
\r
179 // it's too small to resize.
\r
180 copy($original_img, $profile_img);
\r
183 $msg->addFeedback('PROFILE_UPDATED');
\r
185 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
189 require(AT_INCLUDE_PATH.'header.inc.php');
\r
192 <?php include("lib/profile_menu.inc.php") ?>
\r
193 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>?member_id=<?php echo $member_id; ?>" name="form">
\r
194 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_config['prof_pic_max_file_size']; ?>" />
\r
195 <div class="input-form">
\r
196 <?php if (profile_image_exists($member_id)): ?>
\r
198 <a href="get_profile_img.php?id=<?php echo $member_id.SEP.'size=o'; ?>"><img src="get_profile_img.php?id=<?php echo $member_id; ?>" alt="" /></a>
\r
199 <input type="checkbox" name="delete" value="1" id="del"/><label for="del"><?php echo _AT('delete'); ?></label>
\r
203 <h3><?php echo _AT('upload_new_picture'); ?></h3>
\r
204 <input type="file" name="file" /> (<?php echo implode(', ', $supported_images); ?>)</div>
\r
206 <div class="row buttons">
\r
207 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" />
\r
208 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
213 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>