Avatar resize in core

https://www.phpbb.com/ideas/
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Avatar resize in core

Post by SalazarAG »

It would be interesting if phpbb had the resize avatars feature by default. The admin sets the maximum dimensions (in px) in the ACP and when the user enters an avatar larger than the one defined in the ACP will be resized.
I'm sorry for my English. Google Translator does a bad job. :D
koraldon
Registered User
Posts: 530
Joined: Sat Jun 30, 2007 12:42 pm

Re: Avatar resize in core

Post by koraldon »

I know my users find it difficult indeed to use avatars, this will make it much easier to use.
User avatar
jsebean
Registered User
Posts: 378
Joined: Sat Dec 12, 2009 3:20 pm
Location: Atlantic Canada
Name: Jonah
Contact:

Re: Avatar resize in core

Post by jsebean »

This semi-exists with just using gravatar.
-Jonah
:lol:
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Avatar resize in core

Post by thecoalman »

I would suggest the following.
  • Pluplaod for upload which can handle resizing and EXIF client side.
  • Setting for max size of avatar only effects avatar itself because...
  • Avatar is linked to profile, use thumbnail size image on profile page.
  • Link from thumbnail on profile page to full sized image.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Tomba
Registered User
Posts: 143
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: Avatar resize in core

Post by Tomba »

Some code already exists for this. It only needs to be adapted and fitted into the core I think.
http://jrpickeral.com/?p=255

Various board system already support this, so a no-brainer to add this.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Avatar resize in core

Post by david63 »

Tomba wrote: Sun Nov 19, 2017 7:45 pm Some code already exists for this
That link is for phpBB 3.0
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: Avatar resize in core

Post by SalazarAG »

I already know these tutorials, and Dion Design (for 3.2) really works. But the problem is that it is stressful to make this snippet every time you have to upgrade the forum to another version, which is why it would be cool if resizing avatars was a default feature. .
I'm sorry for my English. Google Translator does a bad job. :D
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Avatar resize in core

Post by Ger »

I've tried to wrap my head around this for an extension, but the upload process is bugging me. Basically the only point in the entire process to hook into is core.avatar_driver_upload_move_file_before. I'm capable of resizing the file, but I cannot overwrite the protected width and height properties of the $file class. Therefore the $file->move_file() method decides that the image is still too large, aborts and throws an error.

Sorry guys, guess you'll have to wait for this to get into the core. :(
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Avatar resize in core

Post by mrgoldy »

Ger wrote: Fri Feb 02, 2018 1:55 pm
Just a thought, but if you're sure you've resized it to the correct/allowed dimensions, you could overwrite the 'allowed dimensions' from the upload class, to unlimited or original image size +1px or something like that?
Not sure if it's possible, but just an idea.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Avatar resize in core

Post by thecoalman »

Ger wrote: Fri Feb 02, 2018 1:55 pm I've tried to wrap my head around this for an extension, but the upload process is bugging me. Basically the only point in the entire process to hook into is core.avatar_driver_upload_move_file_before. I'm capable of resizing the file, but I cannot overwrite the protected width and height properties of the $file class. Therefore the $file->move_file() method decides that the image is still too large, aborts and throws an error.

Sorry guys, guess you'll have to wait for this to get into the core. :(
Correct me if I'm wrong here but could not the extension have it's own settings for what it will be resized to? Setting the dimensions in the core to a high amount and only used as a limit on the uploaded file size, yes?

I implemented this with a couple of lines editing core files, it's easy to do because I'm using imagemagick and that is basically how it works on my forum. In my case the resized dimensions are hard coded.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Avatar resize in core

Post by Ger »

posey wrote: Fri Feb 02, 2018 4:01 pm Just a thought, but if you're sure you've resized it to the correct/allowed dimensions, you could overwrite the 'allowed dimensions' from the upload class, to unlimited or original image size +1px or something like that?
Not sure if it's possible, but just an idea.
That was the easiest option, but the dimensions are of course in the config and there is no sane event to hook into before the avatar processing is done. Actually, I see only core.common but that's the most ugly way to do this. @Thecoalmans approach seems more logical:
thecoalman wrote: Fri Feb 02, 2018 8:46 pm Correct me if I'm wrong here but could not the extension have it's own settings for what it will be resized to? Setting the dimensions in the core to a high amount and only used as a limit on the uploaded file size, yes?

I implemented this with a couple of lines editing core files, it's easy to do because I'm using imagemagick and that is basically how it works on my forum. In my case the resized dimensions are hard coded.
This can indeed work: setting the config values to idiot amounts to make sure every image is processed and then overwrite the whole thing using extension settings (either hard coded or ger_avatarresize_max_height and such).

In any case, everything feels hacky. If the properties phpbb\files\filespec::width phpbb\files\filespec::height where public instead of protected it should be a very easy extension. Or create a setter function for them, like

Code: Select all

public function dimensions_set($width, $height) 
{
	if (is_int($width) && is_int($height))
	{
		if (!empty($width)) 
		{
			$this->width = $width;
		}
		if (!empty($height)) 
		{
			$this->height = $height;
		}
	}
	return $this;
}
That way any extension can do to uploaded images whatever they want to as long as they provide integer values for dimensions. All checks can be done as usual and extensions can work without hacky work-arounds or needing to add extra data and processing to the mix.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Avatar resize in core

Post by thecoalman »

Ger wrote: Mon Feb 05, 2018 10:34 am In any case, everything feels hacky.
I don't think it's hacky, the admin may want to set a limit for upload. Those images are converted server side as I'm sure you are aware. I don't know if it's improved but the GD library will consume a lot of RAM for conversion and can easily exceed the RAM limits in the past. If I recall correctly am image with a width of about 5000px was pushing the limits for a 256MB value set for the max RAM a script could consume. If I understand correctly GD converts to uncompressed before conversion hence the reason it will consume so much RAM. Hopefully future version of phpBB utilize plupload for this.

As far as hardcoding the resized value that works for me but I'm sure most people will want to set their own value.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Avatar resize in core

Post by Ger »

thecoalman wrote: Mon Feb 05, 2018 2:59 pm
Ger wrote: Mon Feb 05, 2018 10:34 am In any case, everything feels hacky.
I don't think it's hacky, the admin may want to set a limit for upload. Those images are converted server side as I'm sure you are aware. I don't know if it's improved but the GD library will consume a lot of RAM for conversion and can easily exceed the RAM limits in the past. If I recall correctly am image with a width of about 5000px was pushing the limits for a 256MB value set for the max RAM a script could consume. If I understand correctly GD converts to uncompressed before conversion hence the reason it will consume so much RAM. Hopefully future version of phpBB utilize plupload for this.

As far as hardcoding the resized value that works for me but I'm sure most people will want to set their own value.
Perhaps I expressed myself wrong. English is not my native language so this happens sometimes :P

What I meant is that in an ideal world you want to have a setting to do what it's intended for, or at least be used at all. Having a setting to deny avatars larger than X pixels, it should deny anything else. In your solution, while technically solid, you set that amount to 5000px while that's certainly not what you want. You actually set it to let any validation pass. In that case, the validation is actually processed but it passes since no uploaded image has those dimensions.

Now I'm sure it works and I understand the benefit of imagemagick vs. the GD library. So your solution works. Even more: phpBB's create_thumbnail() function for attachments also uses imagemagick if available. But of course: you make edits to the core file so any extension doing that would be instantly denied.

If I would create an extension I simple want to use the dimension settings to resize any larger avatar larger to a maximum of those given dimensions. So the description "maximum width/height" would still apply, there's only no error presented to the user but the avatar is resized to those dimensions in the upload process.
I've found quite an easy solution, requiring only 1 change to the core: the event core.avatar_driver_upload_move_file_before should also pass the $file object as var. I've done so locally and with it, I'm perfectly capable to resize any given avatar within the given KB range and store it as desired.

Now I only have to figure out how I get this var added to that event... It's easy to create a PR but does anyone know how I'd have to post and refer to this in the tracker? I've done something like that about a year ago but that didn't go very smooth.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Avatar resize in core

Post by thecoalman »

Ideally you have plupload handle it, have you explored that option? The image would be resized client side to the desired dimensions before upload.

---edit----
There is a bug that may affect this. The EXIF dimensions are used if present instead of determining the actual image size. You would need to alter the pluplaod values to strip the EXIF data before upload.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Avatar resize in core

Post by Ger »

thecoalman wrote: Mon Feb 05, 2018 4:26 pm Ideally you have plupload handle it, have you explored that option?
I've looked at it, but quite frankly I don't have a complete understanding of how plupload actually works or how I should implement it in the avatar upload functionality. I do have quite some experience with resizing on the PHP side of things so it's easier for me to take that approach.

I've created a ticket and a PR to pass the $file object to given event. If that's accepted I'll post my extension in the extension development forum.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
Post Reply

Return to “phpBB Ideas”