2014-02-19, 06:11 PM
Sorry if I didn't post this in the correct area.
I'm currently trying to learn more php so I can accomplish more web developing without requiring so much support. I have experience in other languages so it means interpreting code a lot easier. Today I made a nice little accomplishment I feel.
I wanted to get my avatars on the usercp and portal to resize itself like it does on the postbit if the avatar is too big.
I wanted a system that allows a member to upload any size image(dimension wise) and it will resize it to 125x125 so users don't have to worry about resizing their avatars.
First I just tried setting the resize in the settings to 125x125 and removing the dimension limit. This raised a problem still. I tried uploading a 400x400 avatar and it was the original size in my usercp and portal announcements.
I figured it was a pretty public issue so I googled around a bit and couldn't find a clear answer on how to solve the problem. I did get a hint from a topic I found, I took that hint and opened up my portal.php file, looked for the variable $avatar_width_height. I could have simply change the dimensions from 125x125 in that variable itself but I felt that was the sloppy way of doing it.
I digged around in some other files to see if I could get an idea of how to resize an image in php based off the settings in the configuration tab on the admin panel. I found a piece of code in the memberlist.php file and turned it over to work in portal.php
Find this:
Replace with this:
I used the same concept with my usercp.php
Even though it was just copypasting with a few adjustments , I feel quite proud of myself that I was able to determine what to do by simply looking at it. That is pretty much how I learned the other languages I know, copypasting until I grabbed an understanding of what exactly I was copying and pasting was accomplishing, then I started being able to actual write out code, so it's a milestone for me I guess.
I hope this will be of some help for anyone else that was facing the same issue I was.
I'm currently trying to learn more php so I can accomplish more web developing without requiring so much support. I have experience in other languages so it means interpreting code a lot easier. Today I made a nice little accomplishment I feel.
I wanted to get my avatars on the usercp and portal to resize itself like it does on the postbit if the avatar is too big.
I wanted a system that allows a member to upload any size image(dimension wise) and it will resize it to 125x125 so users don't have to worry about resizing their avatars.
First I just tried setting the resize in the settings to 125x125 and removing the dimension limit. This raised a problem still. I tried uploading a 400x400 avatar and it was the original size in my usercp and portal announcements.
I figured it was a pretty public issue so I googled around a bit and couldn't find a clear answer on how to solve the problem. I did get a hint from a topic I found, I took that hint and opened up my portal.php file, looked for the variable $avatar_width_height. I could have simply change the dimensions from 125x125 in that variable itself but I felt that was the sloppy way of doing it.
I digged around in some other files to see if I could get an idea of how to resize an image in php based off the settings in the configuration tab on the admin panel. I found a piece of code in the memberlist.php file and turned it over to work in portal.php
Find this:
if($avatar_dimensions[0] && $avatar_dimensions[1])
{
$avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
}
Replace with this:
if($avatar_dimensions[0] && $avatar_dimensions[1])
{
list($max_width, $max_height) = explode("x", my_strtolower($mybb->settings['memberlistmaxavatarsize']));
if($avatar_dimensions[0] > $max_width || $avatar_dimensions[1] > $max_height)
{
require_once MYBB_ROOT."inc/functions_image.php";
$scaled_dimensions = scale_image($avatar_dimensions[0], $avatar_dimensions[1], $max_width, $max_height);
$avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\"";
}
else
{
$avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
}
}
I used the same concept with my usercp.php
Even though it was just copypasting with a few adjustments , I feel quite proud of myself that I was able to determine what to do by simply looking at it. That is pretty much how I learned the other languages I know, copypasting until I grabbed an understanding of what exactly I was copying and pasting was accomplishing, then I started being able to actual write out code, so it's a milestone for me I guess.
I hope this will be of some help for anyone else that was facing the same issue I was.