Register Members List Search Today's Posts Mark Forums Read

Reply
 
Mod Options
Auto resizing of avatars Details »
Auto resizing of avatars
Mod Version: 1.00, by Dmitriy (Member) Dmitriy is offline
Developer Last Online: Dec 2002 I like it Show Printable Version Email this Page

This modification is in the archives.
vB Version: 2.2.x Rating: (0 vote - 0 average) Installs: 24
Released: 17 Oct 2002 Last Update: Never Downloads: 0
Not Supported  

Those of you with busy boards know that a lot of times users don't have a clue of how to re-size the
pictures they want to use as avatars.

Someone may want to use a cool pic he has on the hard drive, but the picture size is too big and
user gets error message when trying to upload it as avatar. Many users don't know how to re-size the
picture and they will just give up and nevere upload the avatar.

I was ignoring this for too long, but now I came up with the solution:

This hack will re-size the uploaded avatar on the fly, meaning there are no error messages
when the picture is too large, it will be re-sized automatically before it's inserted into the
database



open the member.php file
find thess lines:

if ($imginfo[0]>$avatarmaxdimension or $imginfo[1]>$avatarmaxdimension) {
@unlink($filename);
eval("standarderror(\"".gettemplate("error_avatarbaddimensions")."\");");
}


replace with these lines:

if ([email protected]($filename)) {
if ($imginfo[0]>$avatarmaxdimension or $imginfo[1]>$avatarmaxdimension) {

$image_width = $imginfo[0];
$image_height= $imginfo[1];
if ($image_height > $image_width)
{
$sizefactor = (double) ($avatarmaxdimension / $image_height);
}
else
{
$sizefactor = (double) ($avatarmaxdimension / $image_width) ;
}


$newwidth = (int) ($image_width * $sizefactor);
$newheight = (int) ($image_height * $sizefactor);

$newsize = $newwidth . "x" . $newheight;

$cmd = "/usr/local/bin/mogrify -resize $newsize "."$filename 2>&1";

exec($cmd, $exec_output, $exec_retval);
if($exec_retval > 0)
{
print "ERROR: exec() error: $exec_output[0]";
}
else
{
print "<P align=\"center\"><b>Image was resized from " . $image_width . "x" .
$image_height . " to $newsize</p>";
}

}

That's all.

Now make sure in your control panel to set a really large max file size in the avatar options because
people may now use any size pictures, so the file size may possibly be over 500K
Don't worry, after the avatar is re-sized, the new file size will be really small.

This hack uses the Mogrify utility from ImageMagick, which is free from imagemagick.org

I have this hack installed on www.examnotes.net/forums

You need at least 1 post in order to upload avatar.

Download Now

Only licensed members can download files, Click Here for more information.

Show Your Support

  • To receive notifications regarding updates -> Click to Mark as Installed.
  • This modification may not be copied, reproduced or published elsewhere without author's permission.
Comments
  #2  
Old 17 Oct 2002, 00:54
NuclioN's Avatar
NuclioN NuclioN is offline
 
Join Date: Aug 2002
Only imagemagic or does it also work with others? It's a good hack but i think our apache is using MD or something like that.
Reply With Quote
  #3  
Old 17 Oct 2002, 00:59
Dmitriy Dmitriy is offline
 
Join Date: Jun 2002
As far as I know GD does not support GIF format, but GD can be used for similar function to re-size the PNG and JPG files (if GD was installed with JPG support)

For me it was more important to support GIF and JPG than PNG and JPG, also ImageMagic can support PNG, I just did not compile it with PNG support, but it's easy to add.

This hack will only work with ImageMagick.

I think GIMP will also have re-size functions but it's more complicated to use GIMP.
Reply With Quote
  #4  
Old 17 Oct 2002, 01:06
Dmitriy Dmitriy is offline
 
Join Date: Jun 2002
By the way, I just added an auto-resize for attached images to keep images under the max size. Basically the same think, edit the functions.php in the same manner (almost):

if ($extension=="gif" or $extension=="jpg" or $extension=="jpeg" or $extension=="jpe" or $extension=="png" or $extension=="swf") { // Picture file
if ([email protected]($attachment)) {
if (($maxattachwidth>0 and $imginfo[0]>$maxattachwidth) or ($maxattachheight>0 and $imginfo[1]>$maxattachheight)) {

$image_width = $imginfo[0];
$image_height= $imginfo[1];

if ($image_width > $maxattachwidth)
{
$sizefactor = (double) ($maxattachwidth / $image_width);
}
elseif ($image_height > $maxattachheight)
{
$sizefactor = (double) ($maxattachheight / $image_height) ;
}


$newwidth = (int) ($image_width * $sizefactor);
$newheight = (int) ($image_height * $sizefactor);

$newsize = $newwidth . "x" . $newheight;

$cmd = "/usr/local/bin/mogrify -resize $newsize "."$attachment 2>&1";

exec($cmd, $exec_output, $exec_retval);
if($exec_retval > 0)
{
print "ERROR: exec() error: $exec_output[0]";
}
else
{
print "<P align=\"center\"><b>Image was resized from " . $image_width . "x" .
$image_height . " to $newsize</p>";
}

}
Reply With Quote
  #5  
Old 17 Oct 2002, 01:24
NuclioN's Avatar
NuclioN NuclioN is offline
 
Join Date: Aug 2002
I've requested the imagemagic by our sysop, i hope he will use his common sense.
Reply With Quote
  #6  
Old 17 Oct 2002, 05:05
LangTuDaTinh LangTuDaTinh is offline
 
Join Date: Dec 2001
this hack doesn't work /w 2.2.7 right? because i got this error

Parse error: parse error, unexpected $ in /home/tvseries/public_html/forums/member.php on line 1621

can u modify it so it would work /w 2.2.7 too. thanks
Reply With Quote
  #7  
Old 17 Oct 2002, 05:09
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Good idea. Good job.
Reply With Quote
  #8  
Old 17 Oct 2002, 09:45
Talisman's Avatar
Talisman Talisman is offline
 
Join Date: Aug 2002
Won't work with 2.2.6 either, so will have to come back for this one sometime later. Bummer.
__________________
Don't wear perfume in the garden, unless you want to be pollinated by bees.
Reply With Quote
  #9  
Old 17 Oct 2002, 11:26
Dmitriy Dmitriy is offline
 
Join Date: Jun 2002
It should work with any version of 2.2.X but you MUST have the ImageMagick installed on your server with support for GIF and JPG format.

If you don't have ImageMagick installed you will get parse errors.
Reply With Quote
  #10  
Old 17 Oct 2002, 15:33
FleaBag's Avatar
FleaBag FleaBag is offline
 
Join Date: Dec 2001
Nice hack.
Reply With Quote
  #11  
Old 17 Oct 2002, 18:14
Talisman's Avatar
Talisman Talisman is offline
 
Join Date: Aug 2002
It should work with any version of 2.2.X but you MUST have the ImageMagick installed on your server with support for GIF and JPG format.
Ok, that's it then. Thanks.
Reply With Quote
  #12  
Old 17 Oct 2002, 18:22
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Real name: Dean Clatworthy
awesome idea mate !

- miSt
__________________
Dean Clatworthy - Web Developer/Designer
Reply With Quote
  #13  
Old 17 Oct 2002, 20:12
Crinos's Avatar
Crinos Crinos is offline
 
Join Date: Nov 2001
Real name: Tolitz Rosel
hmmm ... it's a bummer that I need to specify a bigger file size beforehand for this hack to work ... I keep max avatar file sizes at 7Kb, to discourage people from using those animated GIFs that may fulfill the dimension requirements, but are almost 50Kb+ in size...

So, great hack, but I'll pass
__________________
Open Tech Support
http://www.opentechsupport.net
Reply With Quote
  #14  
Old 23 Oct 2002, 06:37
alkatraz alkatraz is offline
 
Join Date: Oct 2002
Location: Vancouver, Canada
Real name: Colin
Thx!
where do I add the attachment hack tho?
__________________
-alkatraz
Northwest Nissans Classifeds
Reply With Quote
  #15  
Old 23 Oct 2002, 11:38
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Real name: Chris Murphy, BSc
admin/functions.php

Satan
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Mod Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 21:06.

Layout Options | Width: Wide Color: