If you are like me, you’ve always wanted to have members avatars and photos resized automatically upon upload, without asking people to do that manually.
ExpressionEngine 2.4 and prior do not resize member’s photos and avatars “out of the box”. You have to ask people upload files of certain dimension and them probably use some plugin to resize the image in the template (which leads to unnecessary server load).
Fortunately, EE 2 offers complete integration of CodeIgniter libraries, and so you can add automatic resize for profile photos and avatars with just few lines of code.
Unfortunately, you need to make changes to one of core files (but that’s just one file and few lines, so you can easily keep that changes).
So, open /system/expressionengine/libraries/Member.php in your code editor.
In the end of upload_member_images function (around line 378) find the lines that say
$config['max_width'] = $max_width;
$config['max_height'] = $max_height;and comment them out
//$config['max_width'] = $max_width;
//$config['max_height'] = $max_height;Then, find these lines below:
// Do we need to resize?
$width = $file_info['image_width'];
$height = $file_info['image_height'];and BELOW them add
//hack start
if ($width > $max_width || $height > $max_height)
{
$config = array(
'library_path' => $this->EE->config->item('image_library_path'),
'image_library' => $this->EE->config->item('image_resize_protocol'),
'source_image' => $upload_path.$new_filename,
'height' => $max_height,
'width' => $max_width,
'maintain_ratio' => TRUE
);
$this->EE->load->library('image_lib', $config);
$this->EE->image_lib->resize();
$image_data = $this->EE->image_lib->get_image_properties($upload_path.$new_filename, TRUE);
$width = $image_data['width'];
$height = $image_data['height'];
}
//hack endThat’s all. Now all avatars, photos (and signatures) that people upload will be automatically resized to the dimensions that you specified as max width and max height in EE membership preferences.