Changeset 1155 for trunk/common
- Timestamp:
- 11/12/11 17:18:55 (6 months ago)
- Location:
- trunk/common
- Files:
-
- 1 added
- 3 edited
-
attachment.php (modified) (1 diff)
-
avatar.php (added)
-
common.php (modified) (1 diff)
-
db/user.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/attachment.php
r1115 r1155 146 146 } 147 147 148 /** 149 * Resizes an image whose filepath is given by the parameters into a new 150 * location specified by the other parameters 151 * 152 * Returns whether or not the image has been successfully resized 153 * Note that it returns false if the image doesn't have a known file-type 154 * 155 * The $new_filepath parameter if ommited or given as null will result in the 156 * image being outputted directly to the client 157 * 158 * @param array $image_info An array containing information about the 159 * original image: width, height, mime-type 160 * @param string $filepath 161 * @param array $new_image_info An array containing the new width and 162 * height 163 * @param string $new_filepath 164 * @return bool 165 */ 166 function image_resize($image_info, $filepath, $new_image_info, 167 $new_filepath = null) { 168 list($image_width, $image_height, $image_type, $image_attribute) = $image_info; 169 list($new_image_width, $new_image_height) = $new_image_info; 170 171 switch ($image_type) { 172 case IMAGETYPE_GIF: 173 // NOTE: animated GIFs become static. Only the first frame is saved 174 // Seems like a good thing anyway 175 $image = imagecreatefromgif($filepath); 176 $image_resized = imagecreate($new_image_width, $new_image_height); 177 // reset palette and transparent color to that of the original file 178 $trans_col = imagecolortransparent($image); 179 imagepalettecopy($image_resized, $image); 180 imagefill($image_resized, 0, 0, $trans_col); 181 imagecolortransparent($image_resized, $trans_col); 182 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, 183 $new_image_width, $new_image_height, $image_width, 184 $image_height); 185 186 if ($new_filepath != null) { 187 return imagegif($image_resized, $new_filepath); 188 } 189 return imagegif($image_resized); 190 191 case IMAGETYPE_JPEG: 192 $image = imagecreatefromjpeg($filepath); 193 $image_resized = imagecreatetruecolor($new_image_width, 194 $new_image_height); 195 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, 196 $new_image_width, $new_image_height, $image_width, 197 $image_height); 198 199 if ($new_filepath != null) { 200 return imagejpeg($image_resized, $new_filepath); 201 } 202 return imagejpeg($image_resized); 203 204 case IMAGETYPE_PNG: 205 $image = imagecreatefrompng($filepath); 206 $image_resized = imagecreatetruecolor($new_image_width, 207 $new_image_height); 208 // turn off the alpha blending to keep the alpha channel 209 imagealphablending($image_resized, false); 210 // allocate transparent color 211 $col = imagecolorallocatealpha($image_resized, 0, 0, 0, 127); 212 // fill the image with the new color 213 imagefilledrectangle($image_resized, 0, 0, $new_image_width, 214 $new_image_height, $col); 215 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, 216 $new_image_width, $new_image_height, $image_width, 217 $image_height); 218 imagesavealpha($image_resized, true); 219 if ($new_filepath != null) { 220 return imagepng($image_resized, $new_filepath); 221 } 222 return imagepng($image_resized); 223 224 default: 225 // unsupported image type 226 return false; 227 } 228 } 148 229 ?> -
trunk/common/common.php
r1083 r1155 260 260 function is_taggable($obj) { 261 261 return $obj == 'user' || $obj == 'task' || $obj == 'round' || $obj == 'textblock'; 262 } 263 264 /** 265 * Returns whether or not the size type given is an existent one on the site 266 * 267 * @param string $size_type 268 * @return bool 269 */ 270 function is_valid_size_type($size_type) { 271 $size_types = array("full", "tiny", "small", "normal", "forum", "big"); 272 return in_array($size_type, $size_types); 262 273 } 263 274 -
trunk/common/db/user.php
r1110 r1155 168 168 { 169 169 log_assert_valid(user_validate($user)); 170 170 171 171 // Update DB 172 172 db_update("ia_user", $user, "id = ".db_quote($user['id']));
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)