diff options
author | Dries Buytaert <dries@buytaert.net> | 2005-02-01 16:27:43 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2005-02-01 16:27:43 +0000 |
commit | 7ccc5a6b1b4541a11b858e09cbd8244909d89c92 (patch) | |
tree | 0742993a6678e544fb6bb2b28787414d38378b7d /modules/user/user.module | |
parent | 7931c778d75cec00bd0d186da18c08e5dcf9a5c4 (diff) | |
download | brdo-7ccc5a6b1b4541a11b858e09cbd8244909d89c92.tar.gz brdo-7ccc5a6b1b4541a11b858e09cbd8244909d89c92.tar.bz2 |
- Patch #16358 by James: added toolkit to enable better image handling. The avatar code and the upload module have been updated to take advantage of the new image API.
There are 5 main functions that modules may now utilize to handle images:
* image_get_info() - this function checks a file. If it exists and is a valid image file, it will return an array containing things like the pixel dimensions of the image, plus the 'type' and common extension.
* image_scale - resizes a given image to fit within a given width / height dimensions, while maintaining aspect ratio (not distorting the image). This function can be used to generate thumbnails, or ensure a maximum resolution, etc.
* image_resize - similar to image_scale (but will not respect aspect ratio - may well distort the image).
* image_rotate - rotate an image by X degrees
* image_crop - crops an image to a given rectangle (defined as top-left x/y coordinates plus a width & height of the rectangle).
Contribution modules will now be able to rely on these base manipulation functions to offer additional functionality (such as image nodes, photo galleries, advanced image manipulation, etc).
Diffstat (limited to 'modules/user/user.module')
-rw-r--r-- | modules/user/user.module | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index d896367bc..785d72b80 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -227,20 +227,19 @@ function user_validate_picture($file, &$edit, $user) { // Check that uploaded file is an image, with a maximum file size // and maximum height/width. - $extension = strtolower(strrchr($file->filename, '.')); - $size = @getimagesize($file->filepath); + $info = image_get_info($file->filepath); list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85')); - if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array('.gif', '.jpg', '.png', '.jpeg')))) { + if (!$info || !$info['extension']) { form_set_error('picture', t('The uploaded file was not an image.')); } - else if ($file->size > (variable_get('user_picture_file_size', '30') * 1000)) { - form_set_error('picture', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30')))); - } - else if ($size[0] > $maxwidth || $size[1] > $maxheight) { + else if (!image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight)) { form_set_error('picture', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85')))); } - else if ($file = file_save_upload('picture', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid . $extension, 1)) { + else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) { + form_set_error('picture', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30')))); + } + else if ($file = file_save_upload('picture', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid . '.' . $info['extension'], 1)) { $edit['picture'] = $file->filepath; } else { @@ -403,26 +402,8 @@ function user_perm() { */ function user_file_download($file) { if (strpos($file, variable_get('user_picture_path', 'pictures') .'/picture-') === 0) { - list($width, $height, $type, $attr) = @getimagesize(file_create_path($file)); - $types = array( - IMAGETYPE_GIF => 'image/gif', - IMAGETYPE_JPEG => 'image/jpeg', - IMAGETYPE_PNG => 'image/png', - IMAGETYPE_SWF => 'application/x-shockwave-flash', - IMAGETYPE_PSD => 'image/psd', - IMAGETYPE_BMP => 'image/bmp', - IMAGETYPE_TIFF_II => 'image/tiff', - IMAGETYPE_TIFF_MM => 'image/tiff', - IMAGETYPE_JPC => 'application/octet-stream', - IMAGETYPE_JP2 => 'image/jp2', - IMAGETYPE_JPX => 'application/octet-stream', - IMAGETYPE_JB2 => 'application/octet-stream', - IMAGETYPE_SWC => 'application/x-shockwave-flash', - IMAGETYPE_IFF => 'image/iff', - IMAGETYPE_WBMP => 'image/vnd.wap.wbmp', - IMAGETYPE_XBM => 'image/xbm' - ); - return array('Content-type: '. $types[$type]); + $info = image_get_info(file_create_path($file)); + return array('Content-type: '. $info['mime_type']); } } |