Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2013-06-12 10:15:46

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Code to resize Avatars on Upload???

Hey Guys,

This one is really bugging me, I have so many users coming to me requesting assistance uploading Avatars because they don't know how to resize images.

Surely someone has come up with a solution to this? I've been looking for a while now but haven't found anything that works.

My coding skills are rather limited so I'm looking for a pre-built solution and I am happy to contribute a few dollars to have this working if that's what it takes.

Cheers,
Squiggles

Offline

#2 2013-06-12 10:26:04

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,209
Website

Re: Code to resize Avatars on Upload???

Offline

#3 2013-06-12 12:35:52

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

I've tried that one and everything seems to work for admins and mods but regular members get an error when trying to upload an image "You do not have permission to access this page."

And I cant see any option to upload an Avatar via URL??

Offline

#4 2013-06-12 12:39:55

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

Any chance of providing "ONLY" the code to resize the Avatar on upload? I don't want any unnecessary code or features.

If you can provide working code to do this I can offer a PayPal tip for your troubles.

Offline

#5 2013-06-12 12:47:49

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,209
Website

Re: Code to resize Avatars on Upload???

In my mod Upload Mod http://fluxbb.org/forums/viewtopic.php?id=5194 there is function img_resize() for change of the size of pictures.
Use this function.

Offline

#6 2013-06-12 13:16:23

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

Sorry to be a pain, but could you be more specific as to what code is required and where to put it?

I'll take a good look at it tomorrow but if you are able to help me it would be appreciated.

Offline

#7 2013-06-12 14:53:54

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,209
Website

Re: Code to resize Avatars on Upload???

file profile.php

		if (is_uploaded_file($uploaded_file['tmp_name']))
		{
			// Preliminary file check, adequate in most cases
			$allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
			if (!in_array($uploaded_file['type'], $allowed_types))
				message($lang_profile['Bad type']);

			// Make sure the file isn't too big
			if ($uploaded_file['size'] > $pun_config['o_avatars_size'])
				message($lang_profile['Too large'].' '.forum_number_format($pun_config['o_avatars_size']).' '.$lang_profile['bytes'].'.');

			// Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions
			if (!@move_uploaded_file($uploaded_file['tmp_name'], PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp'))
				message($lang_profile['Move failed'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');

			list($width, $height, $type,) = @getimagesize(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');

			// Determine type
			if ($type == IMAGETYPE_GIF)
				$extension = '.gif';
			else if ($type == IMAGETYPE_JPEG)
				$extension = '.jpg';
			else if ($type == IMAGETYPE_PNG)
				$extension = '.png';
			else
			{
				// Invalid type
				@unlink(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
				message($lang_profile['Bad type']);
			}

			// Now check the width/height
			if (empty($width) || empty($height) || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
			{
				@unlink(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
				message($lang_profile['Too wide or high'].' '.$pun_config['o_avatars_width'].'x'.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].'.');
			}

			// Delete any old avatars and put the new one in place
			delete_avatar($id);
			@rename(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp', PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.$extension);
			@chmod(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.$extension, 0644);
		}
		else
			message($lang_profile['Unknown failure']);

-->

		if (is_uploaded_file($uploaded_file['tmp_name']))
		{
			// Preliminary file check, adequate in most cases
			$allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
			if (!in_array($uploaded_file['type'], $allowed_types))
				message($lang_profile['Bad type']);

			// Make sure the file isn't too big
//			if ($uploaded_file['size'] > $pun_config['o_avatars_size'])
//				message($lang_profile['Too large'].' '.forum_number_format($pun_config['o_avatars_size']).' '.$lang_profile['bytes'].'.');

			// Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions
			if (!@move_uploaded_file($uploaded_file['tmp_name'], PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp'))
				message($lang_profile['Move failed'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');

			list($width, $height, $type,) = @getimagesize(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');

			// Determine type
			if ($type == IMAGETYPE_GIF)
				$extension = '.gif';
			else if ($type == IMAGETYPE_JPEG)
				$extension = '.jpg';
			else if ($type == IMAGETYPE_PNG)
				$extension = '.png';
			else
			{
				// Invalid type
				@unlink(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
				message($lang_profile['Bad type']);
			}

			// Now check the width/height
			if (empty($width) || empty($height)) //  || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
			{
				@unlink(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
				message($lang_profile['Too wide or high'].' '.$pun_config['o_avatars_width'].'x'.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].'.');
			}

			// resize
			if ($uploaded_file['size'] > $pun_config['o_avatars_size'] || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
			{
				require PUN_ROOT.'include/upload.php';
				
				delete_avatar($id);
				if (img_resize(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp', $pun_config['o_avatars_dir'].'/', $id, str_replace('.', '', $extension), $pun_config['o_avatars_width'], $pun_config['o_avatars_height']) === false)
					message('Error of resize');

				redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar upload redirect']);
			}
			// Delete any old avatars and put the new one in place
			delete_avatar($id);
			@rename(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp', PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.$extension);
			@chmod(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.$extension, 0644);
		}
		else
			message($lang_profile['Unknown failure']);

and

						<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $pun_config['o_avatars_size'] ?>" />

-->

						<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />

Offline

#8 2013-06-12 16:08:04

Smurf
Member
From: Wales - UK
Registered: 2010-09-19
Posts: 37
Website

Re: Code to resize Avatars on Upload???

Squiggles wrote:

I've tried that one and everything seems to work for admins and mods but regular members get an error when trying to upload an image "You do not have permission to access this page."

Could that be a problem with incorrect access permissions on the folder the avatars go to? Try to CHMOD the folder to 777 and see if people can upload. If they can then drop it down to (I think) 644 and see if they still can.

Offline

#9 2013-06-12 16:17:07

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,639
Website

Re: Code to resize Avatars on Upload???

But then administrators wouldn't be able to do this either.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#10 2013-06-12 21:46:47

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

I added the code but receive this error when trying to upload an Avatar afterwards.

Warning: require(/home/x1009xx/public_html/devboard01/include/upload.php) [function.require]: failed to open stream: No such file or directory in /home/x1009xx/public_html/devboard01/profile.php on line 405

Fatal error: require() [function.require]: Failed opening required '/home/x1009xx/public_html/devboard01/include/upload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/x1009xx/public_html/devboard01/profile.php on line 405

Last edited by Squiggles (2013-06-12 21:47:34)

Offline

#11 2013-06-13 01:21:46

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,209
Website

Re: Code to resize Avatars on Upload???

Smurf wrote:
Squiggles wrote:

I've tried that one and everything seems to work for admins and mods but regular members get an error when trying to upload an image "You do not have permission to access this page."

Could that be a problem with incorrect access permissions on the folder the avatars go to? Try to CHMOD the folder to 777 and see if people can upload. If they can then drop it down to (I think) 644 and see if they still can.

It is an error of modification.
Here I wrote about it http://fluxbb.org/forums/viewtopic.php?pid=51714#p51714

Offline

#12 2013-06-13 01:24:46

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,209
Website

Re: Code to resize Avatars on Upload???

Squiggles wrote:

I added the code but receive this error when trying to upload an Avatar afterwards.

Warning: require(/home/x1009xx/public_html/devboard01/include/upload.php) [function.require]: failed to open stream: No such file or directory in /home/x1009xx/public_html/devboard01/profile.php on line 405

Fatal error: require() [function.require]: Failed opening required '/home/x1009xx/public_html/devboard01/include/upload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/x1009xx/public_html/devboard01/profile.php on line 405

Use files
/include/upload.php
/lang/English/upload.php
from my modification "Upload Mod".

Offline

#13 2013-06-14 02:14:58

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

Now you have lost me hmm

Offline

#14 2013-06-17 05:30:57

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

Is there any chance on someone making a (working) mod just to re-size Avatars on upload? This function is important to my site and I'm not a coder so I can't create one myself hmm

It doesn't need to anything other than re-size Avatars on upload.

Offline

#15 2013-06-17 06:04:26

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,209
Website

Re: Code to resize Avatars on Upload???

I gave you the ready decision only for resize an avatar.
You don't want to use it, employ the programmer.

Offline

#16 2013-06-17 08:50:10

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Code to resize Avatars on Upload???

Thanks I got it working.

Would you know how to have it crop the image to 1:1 scale as well?

Offline

Board footer

Powered by FluxBB