Automatic avatar resize on 3.0.11?

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Get Involved
Locked
spomsta
Registered User
Posts: 23
Joined: Thu Aug 01, 2013 10:01 am

Automatic avatar resize on 3.0.11?

Post by spomsta » Mon Aug 19, 2013 5:11 am

Hello,

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

Thanks in advance

SwT-CarbonzZ
Registered User
Posts: 575
Joined: Tue Oct 12, 2010 7:17 am

Re: Automatic avatar resize on 3.0.11?

Post by SwT-CarbonzZ » Mon Aug 19, 2013 6:35 pm

Follow the steps in the link and it will work ;)

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

josegf
Registered User
Posts: 9
Joined: Mon Jan 12, 2015 7:59 pm

Re: Automatic avatar resize on 3.0.11?

Post by josegf » Fri Sep 11, 2015 12:17 pm

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

dan filipi
Registered User
Posts: 82
Joined: Fri Dec 21, 2007 6:36 pm

Re: Automatic avatar resize on 3.0.11?

Post by dan filipi » Tue Sep 29, 2015 5:17 am

The above code does exactly what I've needed on my forum.
So much simpler now for users to upload their avatar. Thanks!

Locked

Return to “[3.0.x] MOD Requests”

Who is online

Users browsing this forum: No registered users and 22 guests