Page 4 of 4

Re: avatar autoresize

Posted: Tue May 10, 2016 2:17 pm
by danny94
Something new on it ?

Re: avatar autoresize

Posted: Wed Jul 20, 2016 12:03 am
by voom
josegf wrote: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
This is actually great, except as others mentioned it breaks attachment upload. But there is a simple solution :)

The additional code goes within the move_file function. At the beginning add $mode to the variables this function reads:

Code: Select all

global $user, $phpbb_root_path, $mode;
Then replace the second code-snippet from above with:

Code: Select all

if ($mode == 'avatar') { $this->resize_image($this->filename,$this->upload->max_width,$this->upload->max_height); }
Now the resize function will only affect the avatar-uploads...

Re: avatar autoresize

Posted: Tue Aug 16, 2016 3:14 pm
by danny94
Thanks man,
had this problem with broken attachment upload with this function. Now it works like a charm.
Thanks.

Re: avatar autoresize

Posted: Wed Jan 04, 2017 3:55 pm
by designer2k2
Hello,

how does this apply for 3.2?

there is no includes/functions_upload.php anymore...

Re: avatar autoresize

Posted: Fri Jan 06, 2017 11:21 pm
by Neuropass
designer2k2 wrote: Wed Jan 04, 2017 3:55 pm Hello,

how does this apply for 3.2?

there is no includes/functions_upload.php anymore...
Scroll to the bottom:
http://sitesplat.com/phpBB3/viewtopic.p ... 476#p16476

Re: avatar autoresize

Posted: Sat Jan 07, 2017 5:10 am
by designer2k2
The BBavatarResize looks interesting, but also a bit overkill for just resizing an uploaded image.

Also i do not want to buy a theme, i just want a extension that works on a 3.2 prosilver based forum...

EDIT:

searched a bit, and found this:

core.avatar_driver_upload_move_file_before

its inside phpbb/avatar/driver/upload.php "Before moving new file in place (and eventually overwriting the existing avatar with the newly uploaded avatar)"

That sounds like the right spot, or?

Re: avatar autoresize

Posted: Sun Feb 12, 2017 4:51 pm

Re: avatar autoresize

Posted: Sun Feb 12, 2017 5:09 pm
by girello
hi anv! i download and install it!
i try it but i have this error:

[phpBB Debug] PHP Warning: in file [ROOT]/ext/bb3mobi/AvatarUpload/core/resize.php on line 69: include(./includes/functions_upload.php): failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/ext/bb3mobi/AvatarUpload/core/resize.php on line 69: include(./includes/functions_upload.php): failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/ext/bb3mobi/AvatarUpload/core/resize.php on line 69: include(): Failed opening './includes/functions_upload.php' for inclusion (include_path='.:/php5.6/lib/php/')

Fatal error: Class 'fileupload' not found in /web/htdocs/www.photolandia.net/home/ext/bb3mobi/Av ... resize.php on line 72

Re: avatar autoresize

Posted: Sun Feb 12, 2017 5:35 pm
In phpBB3.2 no functions_upload.php

Well, we find))

Re: avatar autoresize

Posted: Sun Feb 12, 2017 6:35 pm

Re: avatar autoresize

Posted: Sun Feb 12, 2017 6:38 pm
by girello
[email protected] wrote: Sun Feb 12, 2017 6:35 pm Extension Avatar Upload Resize for phpBB3.2
tnx anvar, now i try it

Re: avatar autoresize

Posted: Mon Mar 06, 2017 10:17 am
by deanmoke
[email protected] wrote: Sun Feb 12, 2017 6:35 pm Extension Avatar Upload Resize for phpBB3.2
Works for me!
Thanks [email protected]
Dean

Re: avatar autoresize

Posted: Tue Apr 25, 2017 10:35 pm
by epi4dogs
[email protected] wrote: Sun Feb 12, 2017 6:35 pm Extension Avatar Upload Resize for phpBB3.2
Hi Anvar,

I was excited to find your resize & crop extension here http://bb3.mobi/forum/viewtopic.php?t=234 but after installing on 3.2 I get the following error:

[phpBB Debug] PHP Warning: in file [ROOT]/ext/bb3mobi/AvatarUpload/core/resize.php on line 83: include(./includes/functions_upload.php): failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/ext/bb3mobi/AvatarUpload/core/resize.php on line 83: include(./includes/functions_upload.php): failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/ext/bb3mobi/AvatarUpload/core/resize.php on line 83: include(): Failed opening './includes/functions_upload.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')

Fatal error: Class 'fileupload' not found in /home/bigbl2/public_html/.../phpBB/ext/bb3mobi/AvatarUpload/core/resize.php on line 86

Any ideas?