Page 1 of 1

Automatic avatar resize on 3.0.11?

Posted: Mon Aug 19, 2013 5:11 am
by spomsta
Hello,

Do you know a mod working for 3.0.11 which can resize automatically avatar when a user upload one?

Thanks in advance

Re: Automatic avatar resize on 3.0.11?

Posted: Mon Aug 19, 2013 6:35 pm
by SwT-CarbonzZ
Follow the steps in the link and it will work ;)

http://forum.dion-designs.com/viewtopic.php?t=8854

Re: Automatic avatar resize on 3.0.11?

Posted: Fri Sep 11, 2015 12:17 pm
by josegf
I created a solution, I hope this helps you.

You'll need PHP 5.5 in your server and PHP GD library. (Probably you have, it's very common config many wordpress theme uses PHP GD library)

Then you need to edit includes/functions_upload.php, locate a function called "move_file"

Before this function you need to add the following code:

Code: Select all

	function resize_image($file, $w, $h, $crop=FALSE)
	{
		list($width, $height) = getimagesize($file);
		$r = $width / $height;
		if ($crop) {
			if ($width > $height) {
				$width = ceil($width-($width*abs($r-$w/$h)));
			} else {
				$height = ceil($height-($height*abs($r-$w/$h)));
			}
			$newwidth = $w;
			$newheight = $h;
		} else {
			if ($w/$h > $r) {
				$newwidth = $h*$r;
				$newheight = $h;
			} else {
				$newheight = $w/$r;
				$newwidth = $w;
			}
		}
		if($this->extension == "jpg") $src = imagecreatefromjpeg($file);
		if($this->extension == "png") $src = imagecreatefrompng($file);
		$dst = imagecreatetruecolor($newwidth, $newheight);
		imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
		if($this->extension == "jpg") imagejpeg($dst,$file);
		if($this->extension == "png") imagepng($dst,$file);
	}
then in the move_file function locate the following code:

switch ($upload_mode)

just before this insert this code:

Code: Select all

$this->resize_image($this->filename,$this->upload->max_width,$this->upload->max_height);
And that's all :)

P.D. Please if you distribute/post this solution, please just mention me, thanks.

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code

Re: Automatic avatar resize on 3.0.11?

Posted: Tue Sep 29, 2015 5:17 am
by dan filipi
The above code does exactly what I've needed on my forum.
So much simpler now for users to upload their avatar. Thanks!